#include #include #include #include using namespace std; class Time { public: int hour; int minute; int second; void print24() const; void print12() const; void tick(); void tick(int n); void syncWithSystemTime(); }; // Member function definitions void Time::print24() const { cout << setfill('0') << setw(2) << hour << ":" << setw(2) << minute << ":" << setw(2) << second << " (24-hour format)"; } void Time::print12() const { int h = hour % 12; if (h == 0) h = 12; cout << setfill('0') << setw(2) << h << ":" << setw(2) << minute << ":" << setw(2) << second << (hour < 12 ? " AM" : " PM") << " (12-hour format)"; } void Time::tick() { ++second; if (second >= 60) { second = 0; ++minute; if (minute >= 60) { minute = 0; ++hour; if (hour >= 24) { hour = 0; } } } } void Time::tick(int n) { for (int i = 0; i < n; ++i) { tick(); } } void Time::syncWithSystemTime() { time_t t = time(nullptr); tm* now = localtime(&t); hour = now->tm_hour; minute = now->tm_min; second = now->tm_sec; } int main() { Time currentTime; currentTime.syncWithSystemTime(); cout << "Current time:\n"; currentTime.print24(); cout << endl; currentTime.print12(); cout << endl; Time futureTime = currentTime; futureTime.tick(3671); // Advance 1 hour, 1 minute, and 11 seconds cout << "\nTime after 3671 seconds:\n"; futureTime.print24(); cout << endl; futureTime.print12(); cout << endl; return EXIT_SUCCESS; }