"TOJ 5247" C + + experiment: Time and Date classes

Source: Internet
Author: User
Tags time and date

Describe

Using C + + to implement date class CDate and Time Class CTime, and use multi-inheritance to implement date-time class Cdatetime on sub-basis, so that it can output sample information.

The code in the main function is given, please fill it out, and do not include the code that you have given when committing.

int main () {int y, M, D, hh, MM, Ss;while (CIN>>Y>>M>>D>>HH>>MM>>SS) {cdatetime dt (Y, M,D,HH,MM,SS);d T. Print ();((CDate) DT). Print ();((CTime) DT). Print ();} return 0;}

Input

There are several groups of input data, one row per group, and 6 positive integers per action, representing the year, month, day, hour, minute, and second of a DateTime.

Date information is guaranteed to be valid.

Output

Output date time, date, time, and so on as sample format.

Sample input

2000 3 1 12 9 9

Sample output

2000-3-1 12:9:9
2000-3-1
12:9:9

#include <iostream>using namespacestd;classcdate{protected:        inty,m,d;  Public: CDate (); CDate (intYintMintd): Y (y), M (m), D (d) {}voidPrint () {cout<<y<<"-"<<m<<"-"<<d<<Endl; } };classctime{protected:        intHh,mm,ss;  Public: CTime (); CTime (inthhintMmintss): HH (hh), mm (mm), SS (ss) {}voidPrint () {cout<":"<<mm<<":"<<ss<<Endl; }};classCdatetime: PublicCDate, Publicctime{ Public: Cdatetime (); Cdatetime (intYintMintDinthhintMmintss): CDate (Y,m,d), CTime (HH,MM,SS) {}voidPrint () {cout<<CDate::y<<"-"<<CDate::m<<"-"<<cdate::d <<" "<<CTime::hh<<":"<<CTime::mm<<":"<<CTime::ss<<Endl; }};intMain () {inty, M, D, HH, MM, SS;  while(cin>>y>>m>>d>>hh>>mm>>SS)        {cdatetime dt (Y,M,D,HH,MM,SS); Dt.        Print (); ((CDate) DT).        Print (); ((CTime) DT).    Print (); }    return 0;}

"TOJ 5247" C + + experiment: Time and Date classes

Related Article

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.