// 22.5HV2 Software Engineering II // Unit 2 Exercise 1 #include #include #include "clock.h" // Constructor core of class Clock::Clock(int h=0, int m=0, int s=0): hour(h), minute(m), second(s) {normalise();} // Core of methods void Clock::tick() { second = second + 1; // Add one second; normalise(); } void Clock::show_time() { cout << setfill('0') << setw(2) << hour; cout << ":" << setw(2) << minute << ":" << setw(2) << second << endl; } void Clock::normalise() { minute = minute + second / 60; // change minute if second > 60 hour = hour + minute/60; // change hour if minute > 60 minute = minute%60; // modulo 60 minutes hour = hour%24; // modulo 24 hours second = second%60; // modulo 60 seconds }