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
428 changes: 428 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions Extra1/Extra1.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}") = "Extra1", "Extra1.vcxproj", "{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}"
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
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Debug|x64.ActiveCfg = Debug|x64
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Debug|x64.Build.0 = Debug|x64
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Debug|x86.ActiveCfg = Debug|Win32
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Debug|x86.Build.0 = Debug|Win32
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Release|x64.ActiveCfg = Release|x64
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Release|x64.Build.0 = Release|x64
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Release|x86.ActiveCfg = Release|Win32
{1D46C0B2-358B-4BBA-97D4-B8ADC2B70CBE}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {23589D41-ADFB-4FD9-BFE4-67AC42C56F62}
EndGlobalSection
EndGlobal
135 changes: 135 additions & 0 deletions Extra1/Extra1.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>{1d46c0b2-358b-4bba-97d4-b8adc2b70cbe}</ProjectGuid>
<RootNamespace>Extra1</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 Extra1/Extra1.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="Source Files">
<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="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<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>Source Files</Filter>
</ClCompile>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="extra-task-1.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>
61 changes: 61 additions & 0 deletions Extra1/extra-task-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "extra-task-1.h"

double seconds_difference(double time_1, double time_2)
{
return time_2 - time_1;
}

double hours_difference(double time_1, double time_2)
{
return seconds_difference(time_1, time_2) / 3600.0;
}

double to_float_hours(int hours, int minutes, int seconds)
{
assert(0 <= minutes && minutes < 60 && 0 <= seconds && seconds < 60);
return hours + minutes / 60.0 + seconds / 3600.0;
}

double to_24_hour_clock(double hours)
{
assert(hours >= 0);
return fmod(hours, 24.0);
}

int get_hours(int seconds)
{
assert(seconds >= 0);
return to_24_hour_clock(seconds / 3600);
}

int get_minutes(int seconds)
{
assert(seconds >= 0);
return (seconds % 3600) / 60;
}

int get_seconds(int seconds)
{
assert(seconds >= 0);
return seconds % 60;
}

double time_to_utc(int utc_offset, double time)
{
assert(0.0 <= time && time < 24.0);
double result = time - utc_offset;
result = fmod(result, 24.0);
if (result < 0)
result += 24.0;
return result;
}

double time_from_utc(int utc_offset, double time)
{
assert(0.0 <= time && time < 24.0);
double result = time + utc_offset;
result = fmod(result, 24.0);
if (result < 0)
result += 24.0;
return result;
}
30 changes: 30 additions & 0 deletions Extra1/extra-task-1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once
#include <cassert>
#include <cmath>

// Return the number of seconds that a time in seconds time_2 is later than a time in seconds time_1.
double seconds_difference(double, double);

// Return the number of hours that a time in seconds time_2 is later than a time in seconds time_1.
double hours_difference(double, double);

// Return the total number of hours in the specified number of hours, minutes, and seconds.
double to_float_hours(int, int, int);

// Convert a number of hours since midnight to a 24-hour clock format.
double to_24_hour_clock(double);

// Return the hours part of a time in seconds.
int get_hours(int);

// Return the minutes part of a time in seconds.
int get_minutes(int);

// Return the seconds part of a time in seconds.
int get_seconds(int);

// Return time at UTC+0, where utc_offset is the number of hours away from UTC+0.
double time_to_utc(int, double);

// Return UTC time in time zone utc_offset.
double time_from_utc(int, double);
53 changes: 53 additions & 0 deletions Extra1/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "extra-task-1.h"
#include <iostream>

using namespace std;

void assert_double_equal(double actual, double expected) {
assert(fabs(actual - expected) < DBL_EPSILON);
}

void main()
{
assert_double_equal(seconds_difference(1800.0, 3600.0), 1800.0);
assert_double_equal(seconds_difference(3600.0, 1800.0), -1800.0);
assert_double_equal(seconds_difference(1800.0, 2160.0), 360.0);
assert_double_equal(seconds_difference(1800.0, 1800.0), 0.0);

assert_double_equal(hours_difference(1800.0, 3600.0), 0.5);
assert_double_equal(hours_difference(3600.0, 1800.0), -0.5);
assert_double_equal(hours_difference(1800.0, 2160.0), 0.1);
assert_double_equal(hours_difference(1800.0, 1800.0), 0.0);

assert_double_equal(to_float_hours(0, 15, 0), 0.25);
assert_double_equal(to_float_hours(2, 45, 9), 2.7525);
assert_double_equal(to_float_hours(1, 0, 36), 1.01);

assert_double_equal(to_24_hour_clock(24), 0);
assert_double_equal(to_24_hour_clock(48), 0);
assert_double_equal(to_24_hour_clock(25), 1);
assert_double_equal(to_24_hour_clock(4), 4);
assert_double_equal(to_24_hour_clock(28.5), 4.5);

assert_double_equal(get_hours(3800), 1);
assert_double_equal(get_minutes(3800), 3);
assert_double_equal(get_seconds(3800), 20);

assert_double_equal(time_to_utc(+0, 12.0), 12.0);
assert_double_equal(time_to_utc(+1, 12.0), 11.0);
assert_double_equal(time_to_utc(-1, 12.0), 13.0);
assert_double_equal(time_to_utc(-11, 18.0), 5.0);
assert_double_equal(time_to_utc(-1, 0.0), 1.0);
assert_double_equal(time_to_utc(-1, 23.0), 0.0);

assert_double_equal(time_from_utc(+0, 12.0), 12.0);
assert_double_equal(time_from_utc(+1, 12.0), 13.0);
assert_double_equal(time_from_utc(-1, 12.0), 11.0);
assert_double_equal(time_from_utc(+6, 6.0), 12.0);
assert_double_equal(time_from_utc(-7, 6.0), 23.0);
assert_double_equal(time_from_utc(-1, 0.0), 23.0);
assert_double_equal(time_from_utc(-1, 23.0), 22.0);
assert_double_equal(time_from_utc(+1, 23.0), 0.0);

cout << "All tests passed!" << endl;
}
Loading