//main.cc File #include <iostream> #include "MyTime.h" int main() { MyTime t1, t2; int counter = 0; while(counter < 2){ std::cout << "Enter a time: "; std::cin >> t1; std::cout << "Enter another time: "; std::cin >> t2; if(t1 == t2) std::cout << t1 << " is equal to " << t2 << std::endl; if(t1 < t2) std::cout << t1 << " is less than " << t2 << std::endl; if(t1 <= t2) std::cout << t1 << " is less than or equal to " << t2 << std::endl; std::cout << t1 << " + " << t2 << " = " << t1 + t2 << std::endl; std::cout << t1 << " - " << t2 << " = " << t1 - t2 << std::endl; std::cout << t1 << " * " << t2 << " = " << t1 * t2 << std::endl; std::cout << t1 << " / " << t2 << " = " << t1 / t2 << std::endl; counter++; } return 0; }

---------------------------------------------------------------------------------------------

//MyTime.h File #include <iostream> class MyTime { public: MyTime(int h = 0, int m = 0); void Reset(int h, int m); void input(); void output() const; MyTime operator + (const MyTime& t1) const; MyTime operator - (const MyTime& t1) const; MyTime operator * (const MyTime& t1); MyTime operator / (const MyTime& t1); bool operator == (const MyTime& t1) const; bool operator < (const MyTime& t1) const; bool operator <= (const MyTime& t1) const; int get_hours() const{return hours;} int get_minutes() const{return minutes;} private: void simplify(); int hours; // hours can be > 24 int minutes; // 0 <= minutes <= 59 }; std::istream& operator >>(std::istream& fin, MyTime& t); std::ostream& operator <<(std::ostream& fout, const MyTime& t);

-------------------------------------------------------------------------------------------

//MyTime.cc File #include "MyTime.h" #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; // Constructor MyTime::MyTime(int h, int m){ hours = h; minutes = m; } void MyTime::Reset(int h, int m){ hours = h; minutes = m; } void MyTime::simplify(){ hours += minutes/60; minutes = minutes%60; } void MyTime::input(){ char junk; cin >> hours; cin.get(junk); cin >> minutes; simplify(); } void MyTime::output() const{ cout << hours << ':' << setw(2) << setfill('0') << minutes; } MyTime MyTime::operator +(const MyTime& t1) const{ MyTime tmp; tmp.hours = t1.hours + hours; tmp.minutes = t1.minutes + minutes; tmp.simplify(); return tmp; } MyTime MyTime::operator -(const MyTime& t1) const{ MyTime tmp; tmp.minutes = abs((t1.hours*60+t1.minutes) - (hours*60+minutes)); tmp.simplify(); return tmp; } MyTime MyTime::operator /(const MyTime& t1){ MyTime tmp; tmp.minutes = t1.hours * 60 + t1.minutes; tmp.simplify(); return tmp; } MyTime MyTime::operator *(const MyTime& t1){ MyTime tmp; tmp.minutes = t1.hours * 60 + t1.minutes; tmp.simplify(); return tmp; } bool MyTime::operator == (const MyTime& t1) const{ return t1.hours == hours && t1.minutes == minutes; } bool MyTime::operator < (const MyTime& t1) const{ return (t1.hours * 60 + t1.minutes) < (hours * 60 + minutes); } bool MyTime::operator <=(const MyTime& t1) const{ return (t1 == (hours * 60 + minutes)) || (t1 < (hours * 60 + minutes)); } ostream& operator <<(ostream& fout, const MyTime& t){ t.output(); return fout; } istream& operator >>(istream& fin, MyTime& t){ t.input(); return fin; }