#include<iostream>
using namespace std;
class Time
{
public:
Time(int h,int m,int s):hour(h),minute(m),sec(s){}
void display(){cout<<hour<<":"<<minute<<":"<<sec<<endl;}
protected:
int hour;
int minute;
int sec;
};
class Date
{
public:
Date(int y,int mo,int d):year(y),month(mo),day(d){}
void show(){cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;}
protected:
int year;
int month;
int day;
};
class Timedate:public Date,public Time
{
public:
Timedate(int y,int mo,int d,int h,int m,int s):Date(y,mo,d),Time(h,m,s){}
void displayall(){show();display();}
};
int main()
{
Date d(2009,6,8);
d.show();
Time t(19,47,58);
t.display();
Timedate T(2009,6,8,19,37,50);
T.displayall();
return 0;
}
参考:网页链接
using namespace std;
class Time
{public:Time(int h,int m,int s):hour(h),minute(m),sec(s){}
void display()
{cout<<hour<<":"<<minute<<":"<<sec<<endl;}
protected:
int hour;
int minute;
int sec;
};
class Date
{public:Date(int y,int mo,int d):year(y),month(mo),day(d){}
void show()
{cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;}
protected:int year;int month;int day;};class Timedate:public Date,public Time
{public:Timedate(int y,int mo,int d,int h,int m,int s):Date(y,mo,d),Time(h,m,s){}
void displayall(){show();display();}};
int main()
{Date d(2009,6,8);d.show();
Time t(19,47,58);t.display();
Timedate T(2009,6,8,19,37,50);
T.displayall();
return 0;
}