Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complete bonus task #220

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added C++ bonus/.vs/C++ bonus/v17/.suo
Binary file not shown.
Binary file added C++ bonus/.vs/C++ bonus/v17/Browse.VC.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions C++ bonus/C++ bonus.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.7.34221.43
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "C++ bonus", "C++ bonus\C++ bonus.vcxproj", "{B5C431E0-7691-469A-BA7E-18D06B19F618}"
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
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Debug|x64.ActiveCfg = Debug|x64
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Debug|x64.Build.0 = Debug|x64
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Debug|x86.ActiveCfg = Debug|Win32
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Debug|x86.Build.0 = Debug|Win32
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Release|x64.ActiveCfg = Release|x64
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Release|x64.Build.0 = Release|x64
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Release|x86.ActiveCfg = Release|Win32
{B5C431E0-7691-469A-BA7E-18D06B19F618}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {72C6F8E0-A468-4468-B1A8-65DF1424732C}
EndGlobalSection
EndGlobal
139 changes: 139 additions & 0 deletions C++ bonus/C++ bonus/C++ bonus.vcxproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?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>
<ItemGroup>
<ClCompile Include="extra-task-1.cpp" />
<ClCompile Include="main.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="extra-task-1.h" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>17.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{b5c431e0-7691-469a-ba7e-18d06b19f618}</ProjectGuid>
<RootNamespace>Cbonus</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>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<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>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
30 changes: 30 additions & 0 deletions C++ bonus/C++ bonus/C++ bonus.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>
4 changes: 4 additions & 0 deletions C++ bonus/C++ bonus/C++ bonus.vcxproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>
101 changes: 101 additions & 0 deletions C++ bonus/C++ bonus/extra-task-1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#include "extra-task-1.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.
*/
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.
*/
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
*/
assert(minutes >= 0 && minutes < 60);
assert(seconds >= 0 && seconds < 60);
return hours + (minutes / 60.0) + (seconds / 3600.0);
}

double to_24_hour_clock(double hours)
{
/*
hours is a number of hours since midnight. Return the
hour as seen on a 24-hour clock.

Precondition: hours >= 0

*/
assert(hours >= 0);
double mts = hours - floor(hours);
int hrs = floor(hours);
return (hrs % 24) + mts;
}

/*
Implement three functions
* get_hours
* get_minutes
* get_seconds
They are used to determine the hours part, minutes part and seconds part
of a time in seconds. E.g.:
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) % 4;
}

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)
{
/*
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
*/
double t = time - utc_offset;
if (t < 0)
{
t += 24;
}
else if (t >= 24)
{
t -= 24;
}
return t;
}

double time_from_utc(int utc_offset, double time)
{
/*
Return UTC time in time zone utc_offset.
*/
return time_to_utc(-utc_offset, time);
}
14 changes: 14 additions & 0 deletions C++ bonus/C++ bonus/extra-task-1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#include <assert.h>
#include <cmath>
#include <iostream>
double seconds_difference(double, double);
double hours_difference(double, double);
double to_float_hours(int, int, int);
double to_24_hour_clock(double);
int get_hours(int);
int get_minutes(int);
int get_seconds(int);
double time_to_utc(int,double);
double time_from_utc(int,double);

44 changes: 44 additions & 0 deletions C++ bonus/C++ bonus/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "extra-task-1.h"
int main()
{
//������������ 1 �������
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)) < DBL_EPSILON);
//������������ 2 �������
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)) < DBL_EPSILON);
//������������ 3 �������
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);
//������������ 4 �������
assert(fabs(to_24_hour_clock(24)) < DBL_EPSILON);
assert(fabs(to_24_hour_clock(48)) < DBL_EPSILON);
assert(fabs(to_24_hour_clock(25) - 1) < DBL_EPSILON);
assert(fabs(to_24_hour_clock(4) - 4) < DBL_EPSILON);
assert(fabs(to_24_hour_clock(28.5) - 4.5) < DBL_EPSILON);
//������������ 5 �������
assert(get_hours(3800) == 1);
assert(get_minutes(3800) == 3);
assert(get_seconds(3800) == 20);
//������������ 6 �������
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)) < DBL_EPSILON);
//������������ 7 �������
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);
assert(fabs(time_from_utc(+1, 23.0)) < DBL_EPSILON);
}
11 changes: 11 additions & 0 deletions C++ bonus/C++ bonus/x64/Debug/C++ bonus.exe.recipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ProjectOutputs>
<ProjectOutput>
<FullPath>B:\С++ bonus\cs211-extra-task-1\C++ bonus\x64\Debug\C++ bonus.exe</FullPath>
</ProjectOutput>
</ProjectOutputs>
<ContentFiles />
<SatelliteDlls />
<NonRecipeFileRefs />
</Project>
Binary file added C++ bonus/C++ bonus/x64/Debug/C++ bonus.ilk
Binary file not shown.
3 changes: 3 additions & 0 deletions C++ bonus/C++ bonus/x64/Debug/C++ bonus.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
 extra-task-1.cpp
B:\С++ bonus\cs211-extra-task-1\C++ bonus\C++ bonus\extra-task-1.cpp(45,13): warning C4244: инициализация: преобразование "double" в "int", возможна потеря данных
C++ bonus.vcxproj -> B:\С++ bonus\cs211-extra-task-1\C++ bonus\x64\Debug\C++ bonus.exe
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.37.32822:TargetPlatformVersion=10.0.22621.0:
Debug|x64|B:\С++ bonus\cs211-extra-task-1\C++ bonus\|
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions C++ bonus/C++ bonus/x64/Debug/C++ bonus.tlog/Cl.items.tlog
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
B:\С++ bonus\cs211-extra-task-1\C++ bonus\C++ bonus\extra-task-1.cpp;B:\С++ bonus\cs211-extra-task-1\C++ bonus\C++ bonus\x64\Debug\extra-task-1.obj
B:\С++ bonus\cs211-extra-task-1\C++ bonus\C++ bonus\main.cpp;B:\С++ bonus\cs211-extra-task-1\C++ bonus\C++ bonus\x64\Debug\main.obj
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added C++ bonus/C++ bonus/x64/Debug/extra-task-1.obj
Binary file not shown.
Binary file added C++ bonus/C++ bonus/x64/Debug/main.obj
Binary file not shown.
Binary file added C++ bonus/C++ bonus/x64/Debug/vc143.idb
Binary file not shown.
Binary file added C++ bonus/C++ bonus/x64/Debug/vc143.pdb
Binary file not shown.
Binary file added C++ bonus/x64/Debug/C++ bonus.exe
Binary file not shown.
Binary file added C++ bonus/x64/Debug/C++ bonus.pdb
Binary file not shown.
Loading