Week 8-Operator overloading-Operator Overloading in the Time class, week 8-time

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.