Week 8-Operator overloading-Operator Overloading in the Time class, week 8-time
The Code is as follows:
# Include <iostream> using namespace std; class CTime {private: unsigned short int hour; // when unsigned short int minute; // minute unsigned short int second; // second public: CTime (int h = 0, int m = 0, int s = 0); void setTime (int h, int m, int s); void display (); // two-objective comparison operator heavy load bool operator> (CTime & t); bool operator <(CTime & t); bool operator >=( CTime & t ); bool operator <= (CTime & t); bool operator = (CTime & t); bool o Perator! = (CTime & t); // the overload of the 2nd objective addition and subtraction operator // returns the time, minute, second after the t value. // example t1 (, 25 ), t2 (11,20, 50), t1 + t2 is 19:41:15 CTime operator + (CTime & t); CTime operator-(CTime & t); CTime operator + (int s ); CTime operator-(int s); // CTime operator + = (CTime & c); CTime operator-= (CTime & c ); CTime operator + = (int s); // return the time CTime operator-= (int s) after s; // return the time before s}; CTime :: CTime (int h, int m, int s) {hour = h; minute = m; second = s;} void CT Ime: setTime (int h, int m, int s) {hour = h; minute = m; second = s;} void CTime: display () {cout
Running result:
Learning Experience:
After this project, I feel that I have basically mastered the usage of operator overloading. Great.