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.