// Project Clock // File clock.cpp // Include iomanip to use manipulators // with arguments. #include #include using namespace std; #include "clock.h" Clock::Clock() { hour = 0; min = 0; sec = 0; } Clock::Clock(int h, int m, int s) { hour = h; min = m; sec = s; } void Clock::tick() { sec++; if (sec == 60) { sec = 0; min++; } if (min == 60) { min = 0; hour++; } if (hour == 24) { hour = 0; } } void Clock::display() { // setfill('0') sets the 0 character for // padding on the right. // setw(2) sets the field width for the // next character as 2. cout << setfill('0') << setw(2) << hour << ":" << setw(2) << min << ":" << setw(2) << sec << endl; }