// Based on Skansholm pages 216..229 #include #include #include using namespace std; class Clock { public: Clock():h(0),m(0),s(0){} Clock(int hour, int min, int sec): h(hour%24),m(min%60),s(sec%60){} void set(int hour, int min, int sec) { h=hour%24; m=min%60; s=sec%60; } void tick(); void write( bool write_sec = true ); private: int h,m,s; }; void Clock::tick() { s = (s+1 ) % 60; if(s==0) { m=(m+1)%60; if(m==0) h = (h+1)%24; } } void Clock::write( bool write_sec ) { cout << setw(2) <> hh>> mm>> ss; c.set(hh,mm,ss); cout <<"How many ticks? "; cin >> ss; for (int i =1; i<=ss; i++) { c.tick(); } cout << "The time is now "; c.write(); cout << endl; }