diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a8ec1c46 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.bin +# Visual Studio files +.vs/ +*.user +*.userosscache +*.sln.docstates +*.suo +*.vsidx +*.vssidx \ No newline at end of file diff --git a/Bonus_1.sln b/Bonus_1.sln new file mode 100644 index 00000000..10645617 --- /dev/null +++ b/Bonus_1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36511.14 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Bonus_1", "Bonus_1\Bonus_1.vcxproj", "{CE095845-2DC1-441F-AD1C-7A0C88C49DBB}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Debug|x64.ActiveCfg = Debug|x64 + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Debug|x64.Build.0 = Debug|x64 + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Debug|x86.ActiveCfg = Debug|Win32 + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Debug|x86.Build.0 = Debug|Win32 + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Release|x64.ActiveCfg = Release|x64 + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Release|x64.Build.0 = Release|x64 + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Release|x86.ActiveCfg = Release|Win32 + {CE095845-2DC1-441F-AD1C-7A0C88C49DBB}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AE147D54-D0BE-4963-BAA7-D4DB80EA32EC} + EndGlobalSection +EndGlobal diff --git a/Bonus_1/Bonus_1.vcxproj b/Bonus_1/Bonus_1.vcxproj new file mode 100644 index 00000000..7ff38d88 --- /dev/null +++ b/Bonus_1/Bonus_1.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {ce095845-2dc1-441f-ad1c-7a0c88c49dbb} + Bonus1 + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/Bonus_1/Bonus_1.vcxproj.filters b/Bonus_1/Bonus_1.vcxproj.filters new file mode 100644 index 00000000..0f0c4242 --- /dev/null +++ b/Bonus_1/Bonus_1.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + + + Файлы заголовков + + + \ No newline at end of file diff --git a/extra-task-1.cpp b/Bonus_1/extra-task-1.cpp similarity index 51% rename from extra-task-1.cpp rename to Bonus_1/extra-task-1.cpp index 6c8c1612..49aa7e95 100644 --- a/extra-task-1.cpp +++ b/Bonus_1/extra-task-1.cpp @@ -1,66 +1,24 @@ +#include double seconds_difference(double time_1, double time_2) { - // your implementation goes here... - - /* - Return the number of seconds later that a time in seconds - time_2 is than a time in seconds time_1. - - >>> seconds_difference(1800.0, 3600.0) - 1800.0 - - >>> seconds_difference(3600.0, 1800.0) - -1800.0 - - >>> seconds_difference(1800.0, 2160.0) - 360.0 - - >>> seconds_difference(1800.0, 1800.0) - 0.0 - */ + return time_2 - time_1; } double hours_difference(double time_1, double time_2) { - /* - Return the number of hours later that a time in seconds - time_2 is than a time in seconds time_1. - - >>> hours_difference(1800.0, 3600.0) - 0.5 - - >>> hours_difference(3600.0, 1800.0) - -0.5 - - >>> hours_difference(1800.0, 2160.0) - 0.1 - - >>> hours_difference(1800.0, 1800.0) - 0.0 - */ + return (time_2 - time_1) / 3600.0; } double to_float_hours(int hours, int minutes, int seconds) { - /* - Return the total number of hours in the specified number - of hours, minutes, and seconds. - - Precondition: 0 <= minutes < 60 and 0 <= seconds < 60 - - >>> to_float_hours(0, 15, 0) - 0.25 - - >>> to_float_hours(2, 45, 9) - 2.7525 - - >>> to_float_hours(1, 0, 36) - 1.01 - */ + return hours + minutes / 60.0 + seconds / 3600.0; } double to_24_hour_clock(double hours) { + if (hours < 0) + return 24+hours - 24*static_cast((24+hours)/24); // Error value for negative input + return hours - 24 * static_cast(hours / 24); /* hours is a number of hours since midnight. Return the hour as seen on a 24-hour clock. @@ -108,37 +66,26 @@ 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 static_cast(seconds / 3600) % 24; +} +int get_minutes(int seconds) +{ + return static_cast(seconds / 60) % 60; +} +int get_seconds(int seconds) +{ + return seconds % 60; +} double time_to_utc(int utc_offset, double time) { - /* - Return time at UTC+0, where utc_offset is the number of hours away from - UTC+0. - You may be interested in: - https://en.wikipedia.org/wiki/Coordinated_Universal_Time - - >>> time_to_utc(+0, 12.0) - 12.0 - - >>> time_to_utc(+1, 12.0) - 11.0 - - >>> time_to_utc(-1, 12.0) - 13.0 - - >>> time_to_utc(-11, 18.0) - 5.0 - - >>> time_to_utc(-1, 0.0) - 1.0 - - >>> time_to_utc(-1, 23.0) - 0.0 - */ + return to_24_hour_clock(time - utc_offset); } double time_from_utc(int utc_offset, double time) { + return to_24_hour_clock(time + utc_offset); /* Return UTC time in time zone utc_offset. diff --git a/Bonus_1/extra-task-1.h b/Bonus_1/extra-task-1.h new file mode 100644 index 00000000..aad4724a --- /dev/null +++ b/Bonus_1/extra-task-1.h @@ -0,0 +1,12 @@ +#pragma once +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); + +double time_to_utc(int utc_offset, double time); + +double time_from_utc(int utc_offset, double time); \ No newline at end of file diff --git a/Bonus_1/main.cpp b/Bonus_1/main.cpp new file mode 100644 index 00000000..319f4a02 --- /dev/null +++ b/Bonus_1/main.cpp @@ -0,0 +1,44 @@ +#include +#include +#include "extra-task-1.h" + +using namespace std; + +int main() { + assert(fabs(seconds_difference(1800.0, 3600.0) - 1800.0) <= DBL_EPSILON); + assert(fabs(seconds_difference(3600.0, 1800.0) - (-1800.0)) <= DBL_EPSILON); + assert(fabs(seconds_difference(1800.0, 2160.0) - 360.0) <= DBL_EPSILON); + assert(fabs(seconds_difference(1800.0, 1800.0) - 0.0) <= DBL_EPSILON); + + assert(fabs(hours_difference(1800.0, 3600.0) - 0.5) <= DBL_EPSILON); + assert(fabs(hours_difference(3600.0, 1800.0) - (-0.5)) <= DBL_EPSILON); + assert(fabs(hours_difference(1800.0, 2160.0) - 0.1) <= DBL_EPSILON); + assert(fabs(hours_difference(1800.0, 1800.0) - 0.0) <= DBL_EPSILON); + + assert(fabs(to_float_hours(0, 15, 0) - 0.25) <= DBL_EPSILON); + assert(fabs(to_float_hours(2, 45, 9) - 2.7525) <= DBL_EPSILON); + assert(fabs(to_float_hours(1, 0, 36) - 1.01) <= DBL_EPSILON); + + assert(fabs(to_24_hour_clock(24) - 0) <= DBL_EPSILON); + assert(fabs(to_24_hour_clock(48) - 0) <= DBL_EPSILON); + assert(fabs(to_24_hour_clock(25) - 1) <= DBL_EPSILON); + assert(fabs(to_24_hour_clock(28.5) - 4.5) <= DBL_EPSILON); + + assert(fabs(time_to_utc(+0, 12.0) - 12.0) <= DBL_EPSILON); + assert(fabs(time_to_utc(+1, 12.0) - 11.0) <= DBL_EPSILON); + assert(fabs(time_to_utc(-1, 12.0) - 13.0) <= DBL_EPSILON); + assert(fabs(time_to_utc(-11, 18.0) - 5.0) <= DBL_EPSILON); + assert(fabs(time_to_utc(-1, 0.0) - 1.0) <= DBL_EPSILON); + assert(fabs(time_to_utc(-1, 23.0) - 0.0) <= DBL_EPSILON); + + assert(fabs(time_from_utc(+0, 12.0) - 12.0) <= DBL_EPSILON); + assert(fabs(time_from_utc(+1, 12.0) - 13.0) <= DBL_EPSILON); + assert(fabs(time_from_utc(-1, 12.0) - 11.0) <= DBL_EPSILON); + assert(fabs(time_from_utc(+6, 6.0) - 12.0) <= DBL_EPSILON); + assert(fabs(time_from_utc(-7, 6.0) - 23.0) <= DBL_EPSILON); + assert(fabs(time_from_utc(-1, 0.0) - 23.0) <= DBL_EPSILON); + assert(fabs(time_from_utc(-1, 23.0) - 22.0) <= DBL_EPSILON); + + system("pause"); + return 0; +} \ No newline at end of file diff --git a/Bonus_1/x64/Debug/Bonus_1.exe.recipe b/Bonus_1/x64/Debug/Bonus_1.exe.recipe new file mode 100644 index 00000000..ce2a2e00 --- /dev/null +++ b/Bonus_1/x64/Debug/Bonus_1.exe.recipe @@ -0,0 +1,11 @@ + + + + + C:\Users\nbarv\source\repos\cs211-extra-task-1\x64\Debug\Bonus_1.exe + + + + + + \ No newline at end of file diff --git a/Bonus_1/x64/Debug/Bonus_1.ilk b/Bonus_1/x64/Debug/Bonus_1.ilk new file mode 100644 index 00000000..8b26fcdc Binary files /dev/null and b/Bonus_1/x64/Debug/Bonus_1.ilk differ diff --git a/Bonus_1/x64/Debug/Bonus_1.log b/Bonus_1/x64/Debug/Bonus_1.log new file mode 100644 index 00000000..11f61ec1 --- /dev/null +++ b/Bonus_1/x64/Debug/Bonus_1.log @@ -0,0 +1,2 @@ + main.cpp + Bonus_1.vcxproj -> C:\Users\nbarv\source\repos\cs211-extra-task-1\x64\Debug\Bonus_1.exe diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/Bonus_1.lastbuildstate b/Bonus_1/x64/Debug/Bonus_1.tlog/Bonus_1.lastbuildstate new file mode 100644 index 00000000..484cc857 --- /dev/null +++ b/Bonus_1/x64/Debug/Bonus_1.tlog/Bonus_1.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.44.35207:TargetPlatformVersion=10.0.26100.0: +Debug|x64|C:\Users\nbarv\source\repos\cs211-extra-task-1\| diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/CL.command.1.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/CL.command.1.tlog new file mode 100644 index 00000000..a54db6b1 Binary files /dev/null and b/Bonus_1/x64/Debug/Bonus_1.tlog/CL.command.1.tlog differ diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/CL.read.1.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/CL.read.1.tlog new file mode 100644 index 00000000..9d79de39 Binary files /dev/null and b/Bonus_1/x64/Debug/Bonus_1.tlog/CL.read.1.tlog differ diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/CL.write.1.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/CL.write.1.tlog new file mode 100644 index 00000000..37670945 Binary files /dev/null and b/Bonus_1/x64/Debug/Bonus_1.tlog/CL.write.1.tlog differ diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/Cl.items.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/Cl.items.tlog new file mode 100644 index 00000000..676fbb36 --- /dev/null +++ b/Bonus_1/x64/Debug/Bonus_1.tlog/Cl.items.tlog @@ -0,0 +1,2 @@ +C:\Users\nbarv\source\repos\cs211-extra-task-1\Bonus_1\extra-task-1.cpp;C:\Users\nbarv\source\repos\cs211-extra-task-1\Bonus_1\x64\Debug\extra-task-1.obj +C:\Users\nbarv\source\repos\cs211-extra-task-1\Bonus_1\main.cpp;C:\Users\nbarv\source\repos\cs211-extra-task-1\Bonus_1\x64\Debug\main.obj diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/link.command.1.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/link.command.1.tlog new file mode 100644 index 00000000..e0d4b5e7 Binary files /dev/null and b/Bonus_1/x64/Debug/Bonus_1.tlog/link.command.1.tlog differ diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/link.read.1.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/link.read.1.tlog new file mode 100644 index 00000000..e53596b3 Binary files /dev/null and b/Bonus_1/x64/Debug/Bonus_1.tlog/link.read.1.tlog differ diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/link.secondary.1.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/link.secondary.1.tlog new file mode 100644 index 00000000..3a652dd3 --- /dev/null +++ b/Bonus_1/x64/Debug/Bonus_1.tlog/link.secondary.1.tlog @@ -0,0 +1,2 @@ +^C:\USERS\NBARV\SOURCE\REPOS\CS211-EXTRA-TASK-1\BONUS_1\X64\DEBUG\EXTRA-TASK-1.OBJ|C:\USERS\NBARV\SOURCE\REPOS\CS211-EXTRA-TASK-1\BONUS_1\X64\DEBUG\MAIN.OBJ +C:\Users\nbarv\source\repos\cs211-extra-task-1\Bonus_1\x64\Debug\Bonus_1.ilk diff --git a/Bonus_1/x64/Debug/Bonus_1.tlog/link.write.1.tlog b/Bonus_1/x64/Debug/Bonus_1.tlog/link.write.1.tlog new file mode 100644 index 00000000..e7b6869f Binary files /dev/null and b/Bonus_1/x64/Debug/Bonus_1.tlog/link.write.1.tlog differ diff --git a/Bonus_1/x64/Debug/extra-task-1.obj b/Bonus_1/x64/Debug/extra-task-1.obj new file mode 100644 index 00000000..27ba33cb Binary files /dev/null and b/Bonus_1/x64/Debug/extra-task-1.obj differ diff --git a/Bonus_1/x64/Debug/main.obj b/Bonus_1/x64/Debug/main.obj new file mode 100644 index 00000000..8d01d063 Binary files /dev/null and b/Bonus_1/x64/Debug/main.obj differ diff --git a/Bonus_1/x64/Debug/vc143.idb b/Bonus_1/x64/Debug/vc143.idb new file mode 100644 index 00000000..28b9b1d5 Binary files /dev/null and b/Bonus_1/x64/Debug/vc143.idb differ diff --git a/Bonus_1/x64/Debug/vc143.pdb b/Bonus_1/x64/Debug/vc143.pdb new file mode 100644 index 00000000..2b89f29d Binary files /dev/null and b/Bonus_1/x64/Debug/vc143.pdb differ diff --git a/x64/Debug/Bonus_1.exe b/x64/Debug/Bonus_1.exe new file mode 100644 index 00000000..ba6fa2ce Binary files /dev/null and b/x64/Debug/Bonus_1.exe differ diff --git a/x64/Debug/Bonus_1.pdb b/x64/Debug/Bonus_1.pdb new file mode 100644 index 00000000..1ed5f233 Binary files /dev/null and b/x64/Debug/Bonus_1.pdb differ