From ea27461c19df61cc53c215fceadd1b13aa3cb666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9C=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 12 Oct 2025 22:08:05 +0300 Subject: [PATCH 1/7] add seconds_difference --- .gitignore | 421 ++++++++++++++++++++ Bonus1/Bonus1.cpp | 23 ++ Bonus1/Bonus1.sln | 31 ++ Bonus1/Bonus1.vcxproj | 135 +++++++ Bonus1/Bonus1.vcxproj.filters | 30 ++ extra-task-1.cpp => Bonus1/extra-task-1.cpp | 13 +- Bonus1/extra-task-1.h | 7 + 7 files changed, 655 insertions(+), 5 deletions(-) create mode 100644 .gitignore create mode 100644 Bonus1/Bonus1.cpp create mode 100644 Bonus1/Bonus1.sln create mode 100644 Bonus1/Bonus1.vcxproj create mode 100644 Bonus1/Bonus1.vcxproj.filters rename extra-task-1.cpp => Bonus1/extra-task-1.cpp (95%) create mode 100644 Bonus1/extra-task-1.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..8df737a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1,421 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- Backup*.rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + + + +## VS CODE +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json + + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/modules.xml +# .idea/*.iml +# .idea/modules + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser \ No newline at end of file diff --git a/Bonus1/Bonus1.cpp b/Bonus1/Bonus1.cpp new file mode 100644 index 00000000..64ca7937 --- /dev/null +++ b/Bonus1/Bonus1.cpp @@ -0,0 +1,23 @@ +#include "extra-task-1.h" +#include "float.h" +#include +int main() +{ + /* > 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*/ + + 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); +} + diff --git a/Bonus1/Bonus1.sln b/Bonus1/Bonus1.sln new file mode 100644 index 00000000..637a1a4d --- /dev/null +++ b/Bonus1/Bonus1.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.14.36310.24 d17.14 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Bonus1", "Bonus1.vcxproj", "{484CA9CC-04A2-4EFE-A070-45A7B9F5868B}" +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 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Debug|x64.ActiveCfg = Debug|x64 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Debug|x64.Build.0 = Debug|x64 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Debug|x86.ActiveCfg = Debug|Win32 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Debug|x86.Build.0 = Debug|Win32 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Release|x64.ActiveCfg = Release|x64 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Release|x64.Build.0 = Release|x64 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Release|x86.ActiveCfg = Release|Win32 + {484CA9CC-04A2-4EFE-A070-45A7B9F5868B}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {FBF0AEC6-1293-40CB-9145-F995ABBFC98C} + EndGlobalSection +EndGlobal diff --git a/Bonus1/Bonus1.vcxproj b/Bonus1/Bonus1.vcxproj new file mode 100644 index 00000000..82cd1fab --- /dev/null +++ b/Bonus1/Bonus1.vcxproj @@ -0,0 +1,135 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 17.0 + Win32Proj + {484ca9cc-04a2-4efe-a070-45a7b9f5868b} + 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/Bonus1/Bonus1.vcxproj.filters b/Bonus1/Bonus1.vcxproj.filters new file mode 100644 index 00000000..dfc1b0d9 --- /dev/null +++ b/Bonus1/Bonus1.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/Bonus1/extra-task-1.cpp similarity index 95% rename from extra-task-1.cpp rename to Bonus1/extra-task-1.cpp index 6c8c1612..c856388d 100644 --- a/extra-task-1.cpp +++ b/Bonus1/extra-task-1.cpp @@ -1,6 +1,7 @@ +#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 @@ -18,6 +19,7 @@ double seconds_difference(double time_1, double time_2) >>> seconds_difference(1800.0, 1800.0) 0.0 */ + return 0; } double hours_difference(double time_1, double time_2) @@ -38,6 +40,7 @@ double hours_difference(double time_1, double time_2) >>> hours_difference(1800.0, 1800.0) 0.0 */ + return 0; } double to_float_hours(int hours, int minutes, int seconds) @@ -56,7 +59,7 @@ double to_float_hours(int hours, int minutes, int seconds) >>> to_float_hours(1, 0, 36) 1.01 - */ + */return 0; } double to_24_hour_clock(double hours) @@ -85,7 +88,7 @@ double to_24_hour_clock(double hours) You may wish to inspect various function in to work with integer and fractional part of a hours separately. - */ + */return 0; } /* @@ -134,7 +137,7 @@ double time_to_utc(int utc_offset, double time) >>> time_to_utc(-1, 23.0) 0.0 - */ + */return 0; } double time_from_utc(int utc_offset, double time) @@ -165,5 +168,5 @@ double time_from_utc(int utc_offset, double time) >>> time_from_utc(+1, 23.0) 0.0 - */ + */return 0; } diff --git a/Bonus1/extra-task-1.h b/Bonus1/extra-task-1.h new file mode 100644 index 00000000..ea400560 --- /dev/null +++ b/Bonus1/extra-task-1.h @@ -0,0 +1,7 @@ +#pragma once +#include ; +#include +// Разница в секундах +double seconds_difference(double time_1, double time_2); + + From 32b3b5d574f54305fc5db638bbb593ca4d2601d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9C=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 12 Oct 2025 22:11:54 +0300 Subject: [PATCH 2/7] add hours_difference --- Bonus1/Bonus1.cpp | 17 +++++++++++++++++ Bonus1/extra-task-1.cpp | 4 ++-- Bonus1/extra-task-1.h | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Bonus1/Bonus1.cpp b/Bonus1/Bonus1.cpp index 64ca7937..8059797b 100644 --- a/Bonus1/Bonus1.cpp +++ b/Bonus1/Bonus1.cpp @@ -19,5 +19,22 @@ int main() 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); + + /*>> > 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*/ + + 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); } diff --git a/Bonus1/extra-task-1.cpp b/Bonus1/extra-task-1.cpp index c856388d..ef5423bb 100644 --- a/Bonus1/extra-task-1.cpp +++ b/Bonus1/extra-task-1.cpp @@ -19,7 +19,7 @@ double seconds_difference(double time_1, double time_2) >>> seconds_difference(1800.0, 1800.0) 0.0 */ - return 0; + } double hours_difference(double time_1, double time_2) @@ -40,7 +40,7 @@ double hours_difference(double time_1, double time_2) >>> hours_difference(1800.0, 1800.0) 0.0 */ - return 0; + return static_cast((time_2 - time_1) / 3600); } double to_float_hours(int hours, int minutes, int seconds) diff --git a/Bonus1/extra-task-1.h b/Bonus1/extra-task-1.h index ea400560..aece44c8 100644 --- a/Bonus1/extra-task-1.h +++ b/Bonus1/extra-task-1.h @@ -3,5 +3,7 @@ #include // Разница в секундах double seconds_difference(double time_1, double time_2); +//Разница в часах +double hours_difference(double time_1, double time_2); From 4ad6c8425b182380f106a5e40883201e7049bee8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9C=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 12 Oct 2025 22:15:26 +0300 Subject: [PATCH 3/7] to_float_hours --- Bonus1/Bonus1.cpp | 13 +++++++++++++ Bonus1/extra-task-1.cpp | 5 ++++- Bonus1/extra-task-1.h | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Bonus1/Bonus1.cpp b/Bonus1/Bonus1.cpp index 8059797b..90c8fcee 100644 --- a/Bonus1/Bonus1.cpp +++ b/Bonus1/Bonus1.cpp @@ -36,5 +36,18 @@ int main() 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); + + /*>> > to_float_hours(0, 15, 0) + 0.25 + + >> > to_float_hours(2, 45, 9) + 2.7525 + + >> > to_float_hours(1, 0, 36) + 1.01*/ + + 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); } diff --git a/Bonus1/extra-task-1.cpp b/Bonus1/extra-task-1.cpp index ef5423bb..ab4d4f75 100644 --- a/Bonus1/extra-task-1.cpp +++ b/Bonus1/extra-task-1.cpp @@ -45,6 +45,9 @@ double hours_difference(double time_1, double time_2) double to_float_hours(int hours, int minutes, int seconds) { + assert((minutes >= 0) && (minutes < 60)); + assert((seconds >= 0) && (seconds < 60)); + return double(hours) + double(minutes) / 60 + double(seconds) / 3600; /* Return the total number of hours in the specified number of hours, minutes, and seconds. @@ -59,7 +62,7 @@ double to_float_hours(int hours, int minutes, int seconds) >>> to_float_hours(1, 0, 36) 1.01 - */return 0; + * } double to_24_hour_clock(double hours) diff --git a/Bonus1/extra-task-1.h b/Bonus1/extra-task-1.h index aece44c8..f06f6083 100644 --- a/Bonus1/extra-task-1.h +++ b/Bonus1/extra-task-1.h @@ -5,5 +5,7 @@ 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); From 4935337eaffe6c9d273734cbf7e5d48c087736f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9C=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 12 Oct 2025 22:20:08 +0300 Subject: [PATCH 4/7] to_24_hour_clock --- Bonus1/Bonus1.cpp | 21 +++++++++++++++++++++ Bonus1/extra-task-1.cpp | 10 +++++++--- Bonus1/extra-task-1.h | 2 ++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/Bonus1/Bonus1.cpp b/Bonus1/Bonus1.cpp index 90c8fcee..0808e4dd 100644 --- a/Bonus1/Bonus1.cpp +++ b/Bonus1/Bonus1.cpp @@ -49,5 +49,26 @@ int main() 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); + + /*>> > to_24_hour_clock(24) + 0 + + >> > to_24_hour_clock(48) + 0 + + >> > to_24_hour_clock(25) + 1 + + >> > to_24_hour_clock(4) + 4 + + >> > to_24_hour_clock(28.5) + 4.5*/ + + 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); } diff --git a/Bonus1/extra-task-1.cpp b/Bonus1/extra-task-1.cpp index ab4d4f75..2a9a03bb 100644 --- a/Bonus1/extra-task-1.cpp +++ b/Bonus1/extra-task-1.cpp @@ -61,12 +61,16 @@ double to_float_hours(int hours, int minutes, int seconds) 2.7525 >>> to_float_hours(1, 0, 36) - 1.01 - * + 1.01*/ + } double to_24_hour_clock(double hours) { + assert(hours >= 0); + double hour; + double minute = modf(hours, &hour); + return int(hour) % 24 + minute; /* hours is a number of hours since midnight. Return the hour as seen on a 24-hour clock. @@ -91,7 +95,7 @@ double to_24_hour_clock(double hours) You may wish to inspect various function in to work with integer and fractional part of a hours separately. - */return 0; + */ } /* diff --git a/Bonus1/extra-task-1.h b/Bonus1/extra-task-1.h index f06f6083..0f2b50e8 100644 --- a/Bonus1/extra-task-1.h +++ b/Bonus1/extra-task-1.h @@ -7,5 +7,7 @@ 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); +//Приведение к 24ч типу +double to_24_hour_clock(double hours); From 57e5d9dc4e579b8c0e479f862c6d8ba6c359f939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9C=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 12 Oct 2025 22:23:54 +0300 Subject: [PATCH 5/7] add get(hours,minutes,seconds) --- Bonus1/Bonus1.cpp | 13 +++++++++++++ Bonus1/extra-task-1.cpp | 13 +++++++++++++ Bonus1/extra-task-1.h | 6 ++++++ 3 files changed, 32 insertions(+) diff --git a/Bonus1/Bonus1.cpp b/Bonus1/Bonus1.cpp index 0808e4dd..2b3d9c94 100644 --- a/Bonus1/Bonus1.cpp +++ b/Bonus1/Bonus1.cpp @@ -70,5 +70,18 @@ int main() 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); + + /*>> > get_hours(3800) + 1 + + >> > get_minutes(3800) + 3 + + >> > get_seconds(3800) + 20*/ + + assert(get_hours(3800) == 1); + assert(get_minutes(3800) == 3); + assert(get_seconds(3800) == 20); } diff --git a/Bonus1/extra-task-1.cpp b/Bonus1/extra-task-1.cpp index 2a9a03bb..ae093434 100644 --- a/Bonus1/extra-task-1.cpp +++ b/Bonus1/extra-task-1.cpp @@ -97,7 +97,20 @@ double to_24_hour_clock(double hours) */ } +int get_hours(int sec) +{ + return sec / 3600; +} +int get_minutes(int sec) +{ + return (sec % 3600) / 60; +} + +int get_seconds(int sec) +{ + return (sec % 3600) % 60; +} /* Implement three functions * get_hours diff --git a/Bonus1/extra-task-1.h b/Bonus1/extra-task-1.h index 0f2b50e8..2ace34dc 100644 --- a/Bonus1/extra-task-1.h +++ b/Bonus1/extra-task-1.h @@ -9,5 +9,11 @@ double hours_difference(double time_1, double time_2); double to_float_hours(int hours, int minutes, int seconds); //Приведение к 24ч типу double to_24_hour_clock(double hours); +//Часы после полуночи +int get_hours(int sec); +//Минуты после полуночи +int get_minutes(int sec); +//Секунды после полуночи +int get_seconds(int sec); From 12cdf19167e1efad144e09bf65dd653b83d7527f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9C=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 12 Oct 2025 22:27:19 +0300 Subject: [PATCH 6/7] add time_to_utc --- Bonus1/Bonus1.cpp | 26 ++++++++++++++++++++++++++ Bonus1/extra-task-1.cpp | 3 ++- Bonus1/extra-task-1.h | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Bonus1/Bonus1.cpp b/Bonus1/Bonus1.cpp index 2b3d9c94..528d537c 100644 --- a/Bonus1/Bonus1.cpp +++ b/Bonus1/Bonus1.cpp @@ -83,5 +83,31 @@ int main() assert(get_hours(3800) == 1); assert(get_minutes(3800) == 3); assert(get_seconds(3800) == 20); + + /*>> > 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*/ + + 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); + } diff --git a/Bonus1/extra-task-1.cpp b/Bonus1/extra-task-1.cpp index ae093434..1b61a6a6 100644 --- a/Bonus1/extra-task-1.cpp +++ b/Bonus1/extra-task-1.cpp @@ -134,6 +134,7 @@ int get_seconds(int sec) double time_to_utc(int utc_offset, double time) { + return (time - utc_offset < 0) ? 24 + (time - utc_offset) : to_24_hour_clock(24 + (time - utc_offset)); /* Return time at UTC+0, where utc_offset is the number of hours away from UTC+0. @@ -157,7 +158,7 @@ double time_to_utc(int utc_offset, double time) >>> time_to_utc(-1, 23.0) 0.0 - */return 0; + */ } double time_from_utc(int utc_offset, double time) diff --git a/Bonus1/extra-task-1.h b/Bonus1/extra-task-1.h index 2ace34dc..bf477e21 100644 --- a/Bonus1/extra-task-1.h +++ b/Bonus1/extra-task-1.h @@ -15,5 +15,7 @@ int get_hours(int sec); int get_minutes(int sec); //Секунды после полуночи int get_seconds(int sec); +//Приведение времени от Гринвического меридиана +double time_to_utc(int utc_offset, double time); From e1e02080296d75632835ccb989acb867795d1f68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=9C=D0=B0=D0=BD?= =?UTF-8?q?=D0=BE=D0=B2?= Date: Sun, 12 Oct 2025 22:30:31 +0300 Subject: [PATCH 7/7] add time_from_utc --- Bonus1/Bonus1.cpp | 33 +++++++++++++++++++++++++++++++++ Bonus1/extra-task-1.cpp | 3 ++- Bonus1/extra-task-1.h | 2 ++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Bonus1/Bonus1.cpp b/Bonus1/Bonus1.cpp index 528d537c..a075f22b 100644 --- a/Bonus1/Bonus1.cpp +++ b/Bonus1/Bonus1.cpp @@ -109,5 +109,38 @@ int main() assert(fabs(time_to_utc(-1, 0.0) - 1.0) < DBL_EPSILON); assert(fabs(time_to_utc(-1, 23.0)) < DBL_EPSILON); + /*>> > time_from_utc(+0, 12.0) + 12.0 + + >> > time_from_utc(+1, 12.0) + 13.0 + + >> > time_from_utc(-1, 12.0) + 11.0 + + >> > time_from_utc(+6, 6.0) + 12.0 + + >> > time_from_utc(-7, 6.0) + 23.0 + + >> > time_from_utc(-1, 0.0) + 23.0 + + >> > time_from_utc(-1, 23.0) + 22.0 + + >> > time_from_utc(+1, 23.0) + 0.0*/ + + 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); + } diff --git a/Bonus1/extra-task-1.cpp b/Bonus1/extra-task-1.cpp index 1b61a6a6..7d16787e 100644 --- a/Bonus1/extra-task-1.cpp +++ b/Bonus1/extra-task-1.cpp @@ -163,6 +163,7 @@ double time_to_utc(int utc_offset, double time) double time_from_utc(int utc_offset, double time) { + return (time + utc_offset < 0) ? 24 + (time + utc_offset) : to_24_hour_clock(24 + (time + utc_offset)); /* Return UTC time in time zone utc_offset. @@ -189,5 +190,5 @@ double time_from_utc(int utc_offset, double time) >>> time_from_utc(+1, 23.0) 0.0 - */return 0; + */ } diff --git a/Bonus1/extra-task-1.h b/Bonus1/extra-task-1.h index bf477e21..8fe83e8e 100644 --- a/Bonus1/extra-task-1.h +++ b/Bonus1/extra-task-1.h @@ -17,5 +17,7 @@ int get_minutes(int sec); int get_seconds(int sec); //Приведение времени от Гринвического меридиана double time_to_utc(int utc_offset, double time); +//Приведение времени к Гринвическому меридиану +double time_from_utc(int utc_offset, double time);