#include <iostream>
#include <cmath>
#include <string>
using namespace std;
class Time
{
private:
int hours;
int minutes;
int seconds;
public:
Time(string timeString);
int toSeconds();
void displayTime();
};
class Clock
{
private:
string nameClock;
Time currentTime;
public:
Clock(string clockName, string timeString);
void showElapsedTime();
};
Time::Time(string timeString) : hours(0), minutes(0), seconds(0)
{
int i = 0, n = timeString.length();
while (i < n && timeString[i] != ':')
{
hours = hours * 10 + (timeString[i] - '0');
i++;
}
i++;
while (i < n && timeString[i] != ':')
{
minutes = minutes * 10 + (timeString[i] - '0');
i++;
}
i++;
while (i < n)
{
seconds = seconds * 10 + (timeString[i] - '0');
i++;
}
}
int Time::toSeconds()
{
return hours * 3600 + minutes * 60 + seconds;
}
void Time::displayTime()
{
cout << (hours < 10 ? "0" : "") << hours << ":"
<< (minutes < 10 ? "0" : "") << minutes << ":"
<< (seconds < 10 ? "0" : "") << seconds << '\n';
}
Clock::Clock(string clockName, string timeString) : nameClock(clockName), currentTime(timeString) {}
void Clock::showElapsedTime()
{
cout << "\nClock " << nameClock << " is displaying time: ";
currentTime.displayTime();
cout << "Elapsed time since 00:00:00: " << currentTime.toSeconds() << " seconds.\n";
}
int main()
{
cout << "This program initializes a clock and displays elapsed time in seconds.\n";
cout << "----------------------------------------------------------\n";
string clockName, timeString;
cout << "Enter clock name: ";
getline(cin, clockName);
cout << "Enter current time (HH:MM:SS): ";
getline(cin, timeString);
Clock myClock(clockName, timeString);
myClock.showElapsedTime();
cout << "\nProgram execution completed. Exiting...\n";
return 0;
}