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
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.bin
# Visual Studio files
.vs/
*.user
*.userosscache
*.sln.docstates
*.suo
*.vsidx
*.vssidx
31 changes: 31 additions & 0 deletions Bonus_1.sln
Original file line number Diff line number Diff line change
@@ -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
135 changes: 135 additions & 0 deletions Bonus_1/Bonus_1.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{ce095845-2dc1-441f-ad1c-7a0c88c49dbb}</ProjectGuid>
<RootNamespace>Bonus1</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="extra-task-1.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="extra-task-1.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
30 changes: 30 additions & 0 deletions Bonus_1/Bonus_1.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Исходные файлы">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Файлы заголовков">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Файлы ресурсов">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="extra-task-1.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Исходные файлы</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="extra-task-1.h">
<Filter>Файлы заголовков</Filter>
</ClInclude>
</ItemGroup>
</Project>
95 changes: 21 additions & 74 deletions extra-task-1.cpp → Bonus_1/extra-task-1.cpp
Original file line number Diff line number Diff line change
@@ -1,66 +1,24 @@
#include <math.h>
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<int>((24+hours)/24); // Error value for negative input
return hours - 24 * static_cast<int>(hours / 24);
/*
hours is a number of hours since midnight. Return the
hour as seen on a 24-hour clock.
Expand Down Expand Up @@ -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<int>(seconds / 3600) % 24;
}
int get_minutes(int seconds)
{
return static_cast<int>(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.

Expand Down
12 changes: 12 additions & 0 deletions Bonus_1/extra-task-1.h
Original file line number Diff line number Diff line change
@@ -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);
44 changes: 44 additions & 0 deletions Bonus_1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include <iostream>
#include <cassert>
#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;
}
Loading