// demo program for comp 1672 // Implements the class Time #include #include "time.h" // header file for the time class using namespace std; // Default constructor Time::Time() { hour = 0; min = 0; sec = 0; } // Constructor that allows initialization of data values Time::Time(int h, int m, int s) { set(h, m, s); } // output the time to the screen void Time::print() { cout << hour << ":" << ((min < 10)?"0":"") << min << ":" << ((sec<10)?"0":"") << sec; } // set the time - does all appropriate error handling // except for negative values void Time::set(int h, int m, int s) { hour = min = sec = 0; add_seconds(s); add_minutes(m); add_hours(h); } // increment hours - works on a 24 hour clock void Time:: add_hours(int h) { hour = (hour + h)%24; } // increment minutes - hours is updated if we end up with more than 60 minutes void Time::add_minutes(int m) { add_hours((min+m)/60); min = (min + m)%60; } // increment seconds - minutes and hours are updated appropriately void Time::add_seconds(int s) { add_minutes((sec+s)/60); sec = (sec+s)%60; }