Operator overloading in the time class

Source: Internet
Author: User

Enter the code:

/** Copyright (c) 2015, Yantai University School of Computer * All rights reserved. * File name: Sum123.cpp * Author: Lin Haiyun * Completion date: April 28, 2015 * Version number: v2.0 * * Problem Description: Implement the various operations of the overloaded operator of the time class * Input Description: No * program output: Results of each operation/#inclu    De<iostream>using namespace Std;class ctime{private:unsigned short int hour;  When unsigned short int minute;  Sub unsigned short int second;    Seconds public:ctime (int h=0,int m=0,int s=0);    void settime (int h,int m,int s);    void display ();    function definitions For comparison operation overloads bool operator > (CTime &t);    BOOL operator < (CTime &t);    BOOL operator >= (CTime &t);    BOOL operator <= (CTime &t);    BOOL operator = = (CTime &t);    BOOL operator! = (CTime &t);    The definition of the binary function is CTime operator+ (CTime &t);    CTime operator-(CTime &t); CTime operator+ (int s);//return S seconds after CTime operator-(int s);//return seconds before time//two mesh assignment operator function definition CTime operator+= (CTime &c)    ;    CTime operator-= (CTime &c); CTime operator+= (int s);//Returns the time after S seconds CTime operator-= (int s);//returnss seconds before the time};    Ctime::ctime (int h,int m,int s) {hour=h;    Minute=m; Second=s;}    void ctime::settime (int h,int m,int s) {hour=h;    Minute=m; Second=s;} void CTime::d isplay () {cout<


Operation Result:

Operator overloading in the time class

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.