Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions extra-task-1.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "extra-task-1.h"
double seconds_difference(double time_1, double time_2)
{
// your implementation goes here...

return time_2 - time_1;
/*
Return the number of seconds later that a time in seconds
time_2 is than a time in seconds time_1.
Expand All @@ -22,6 +23,7 @@ double seconds_difference(double time_1, double time_2)

double hours_difference(double time_1, double time_2)
{
return (time_2 - time_1) / 3600;
/*
Return the number of hours later that a time in seconds
time_2 is than a time in seconds time_1.
Expand All @@ -42,6 +44,7 @@ double hours_difference(double time_1, double time_2)

double to_float_hours(int hours, int minutes, int seconds)
{
return hours + minutes / 60.0 + seconds / 3600.0;
/*
Return the total number of hours in the specified number
of hours, minutes, and seconds.
Expand All @@ -61,6 +64,8 @@ double to_float_hours(int hours, int minutes, int seconds)

double to_24_hour_clock(double hours)
{
while (hours >= 24) hours -= 24;
return hours;
/*
hours is a number of hours since midnight. Return the
hour as seen on a 24-hour clock.
Expand Down Expand Up @@ -108,9 +113,21 @@ double to_24_hour_clock(double hours)
In other words, if 3800 seconds have elapsed since midnight,
it is currently 01:03:20 (hh:mm:ss).
*/

int get_hours(int seconds) {
return seconds / 3600;
}
int get_minutes(int seconds) {
return seconds % 3600 / 60;
}
int get_seconds(int seconds) {
return seconds % 60;
}
double time_to_utc(int utc_offset, double time)
{
double a = time - utc_offset;
while (a >= 24) a -= 24;
while (a <= 0) a += 24;
return a;
/*
Return time at UTC+0, where utc_offset is the number of hours away from
UTC+0.
Expand Down Expand Up @@ -139,6 +156,11 @@ double time_to_utc(int utc_offset, double time)

double time_from_utc(int utc_offset, double time)
{
double a = time + utc_offset;
while (a >= 24) a -= 24;
while (a <= 0) a += 24;
return a;

/*
Return UTC time in time zone utc_offset.

Expand Down
19 changes: 19 additions & 0 deletions extra-task-1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once
#include <iostream>
double seconds_difference(double time_1, double time_2);

double hours_difference(double time_1, double time_2);

double to_float_hours(int hours, int minutes, int seconds);

double to_24_hour_clock(double hours);

int get_hours(int seconds);

int get_minutes(int seconds);

int get_seconds(int seconds);

double time_to_utc(int utc_offset, double time);

double time_from_utc(int utc_offset, double time);
32 changes: 32 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "assert.h"
#include "extra-task-1.h"
int main() {
//�������� ������ ������� ������
assert(seconds_difference(1000.5,300.3) == -700.2);
assert(seconds_difference(300.5, 500) == 199.5);
//�������� ������ ������� �����
assert(hours_difference(1800.0, 3600.0) == 0.5);
assert(hours_difference(3600.0, 1800.0) == -0.5);
//������� ������, ����� � ����� � ����
assert(to_float_hours(0, 15, 0) == 0.25);
assert(to_float_hours(2, 45, 9) == 2.7525);
//������� � ���� � ������� ���
assert(to_24_hour_clock(24) == 0);
assert(to_24_hour_clock(25) == 1);
assert(to_24_hour_clock(28.5) == 4.5);
//����� ���������� ����� � ��������
assert(get_hours(3800) == 1);
assert(get_hours(9000) == 2);
//����� ���������� ����� ����� ������ ����� � ��������
assert(get_minutes(3800) == 3);
assert(get_minutes(9000) == 30);
//����� ���������� ������ ����� ������ ����� � ����� � ��������
assert(get_seconds(3800) == 20);
assert(get_seconds(9000) == 0);
//������� � ��������� ���������������� �����
assert(time_to_utc(+1, 12.3) == 11.3);
assert(time_to_utc(-11, 18.5) == 5.5);
//������� �� ��������� ���������������� �����
assert(time_from_utc(-7, 6.7) == 23.7);
assert(time_from_utc(-1, 23.82) == 22.82);
}