WEEK 1 (date and time), week 2 (date and time)

Source: Internet
Author: User

WEEK 1 (date and time), week 2 (date and time)
/*
* Copyright (c) 2015, computer College, Yantai University
* All rights reserved.
* File name: Week 12th (date and time)

* Author: Wang Zhong
* Completion date: 2015.5.27

* Version: v1.0
*
* Problem description: defines a Date type. Data members include year, month, day, SetDate (int y, int m, int d), and PrintDate () the function is used to set the date and display date respectively. Then, a Time class Time is defined. Data members include Time, minute, and second, SetTime (int h, int m, int s), and PrintTime () the functions are used to set the time and display time respectively, and then define a date and time class TimeDate based on the existing methods provided in the two classes to set and display the date and time. Implement the TimeDate class. The following describes the main function used for testing and the reference running result.

* Input description:

* Program output:

#include <iostream>using namespace std;class Date{protected:    int year;    int month;    int day;public:    void SetDate(int y=0,int m=0,int d=0);    void PrintDate();};class Time{protected:    int second;    int minute;    int hour;public:    void SetTime(int h=0,int m=0,int s=0);    void PrintTime();};class TimeDate:virtual public Date,virtual public Time{public:    TimeDate(int y=0,int m=0,int d=0,int h=0,int mi=0,int s=0)    {        SetDate(y,m,d);        SetTime(h,mi,s);    }    void PrintDate_Time();};int main(){    TimeDate dt_a,dt_b(2010,4,16,9,30,0);    cout<<"dt_a: ";    dt_a.PrintDate_Time();    cout<<endl;    cout<<"dt_b: ";    dt_b.PrintDate_Time();    dt_a.SetTime(20,00,00);    dt_a.SetDate(2008,8,7);    cout<<endl;    cout<<"dt_after uptate: ";    dt_a.PrintDate_Time();    return 0;}void Date::SetDate(int y,int m,int d){    year=y;    month=m;    day=d;}void Date::PrintDate(){    cout<<year<<"/"<<month<<"/"<<day<<'\t';}void Time::SetTime(int h,int m,int s){    hour=h;    minute=m;    second=s;}void Time::PrintTime(){    cout<

A problem occurred in the TimeDate constructor. No default parameter exists and the TimeDate constructor cannot run.

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.