The time and date classes are derived from the time and date classes.

Source: Internet
Author: User

Write another application with multiple inheritance types today. The time and date classes are derived from the time and date classes.

Program code

# Include <iostream> using namespace STD; Class date // Date class {public: // constructor date (INT y = 0, int m = 0, int D = 0 ); // set the date void setdate (INT y, int M, int D); // print the date void printdate () {cout <year <"year" <month <"month" <day <"day" <Endl;} protected: int year; // year int month; // month int day; // day}; // Constructor (use the initialization table to initialize data members) Date: Date (INT y, int m, int D): Year (Y), month (M), Day (d) {}// set the date void Date: setdate (INT y, int M, int D) {year = y; month = m; Day = D;} class time // time class {public: // constructor time (INT h = 0, int m = 0, int S = 0); // set the time void settime (int h, int M, int S); // print the time void printtime (); protected: int hour; // int minute; // int second; // second}; // constructor time: Time (int h, int M, int S ): hour (H), minute (M), second (s) {}// set the time void time: settime (int h, int M, int s) {hour = h; minute = m; second = s;} // print time void time: printtime () {cout 


Execution result:


The time and date classes are derived from the time and date classes.

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.