From f18c44909c604a01bb0265d006a84223ee88d603 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 1 Mar 2026 18:33:54 +0200 Subject: feat(Week02): Add solutions --- Week02/Exercise06/time.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Week02/Exercise06/time.cpp (limited to 'Week02/Exercise06/time.cpp') diff --git a/Week02/Exercise06/time.cpp b/Week02/Exercise06/time.cpp new file mode 100644 index 0000000..74b1447 --- /dev/null +++ b/Week02/Exercise06/time.cpp @@ -0,0 +1,19 @@ +#include "time.h" + +unsigned timeToMilliseconds(const Time& t) { + return (t.hour * 60 * 60 + t.minutes * 60 + t.seconds) * 1000; +} + +void Time::Advance(const Time& other) { + // По-простия вариант е с експлицитни сметки, но помислете защо това работи + *this = millisecondsToTime(timeToMilliseconds(*this) + timeToMilliseconds(other)); +} + +Time millisecondsToTime(unsigned int milliseconds) { + Time t; + t.hour = (milliseconds / 1000 / 60 / 60) % 24; + t.minutes = (milliseconds / 1000 / 60) % 60; + t.seconds = (milliseconds / 1000) % 60; + + return t; +} -- cgit v1.3.1-23-gd82d