/*
* 程序的版权和版本声明部分
* Copyright (c)2012, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: object.cpp
* 作者:赵 洋
* 完成日期: 2013年5 月24 日
* 版本号: v1.0
* 输入描述:无
* 问题描述:
* 程序输出:
*/
#include<iostream>
using namespace std;
class Date
{
public:
Date(int y=1,int m=1,int d=1);
void setDate(int,int,int );
void printDate();
protected:
int year,month,day;
};
Date::Date(int y,int m,int d):year(y),month(m),day(d){}
void Date::setDate(int y,int m,int d)
{
year=y;
month=m;
day=d;
}
void Date::printDate()
{
cout<<"年/月/日"<<year<<"/"<<month<<"/"<<day<<endl;;
}
class Time
{
public:
Time(int h=0,int min=0,int s=0);
void setTime(int ,int,int);
void printTime();
protected:
int hour,minute,sec;
};
Time::Time(int h,int min,int s):hour(h),minute(min),sec(s){}
void Time::setTime(int h,int min,int s)
{
hour=h;
minute=min;
sec=s;
}
void Time::printTime()
{
cout<<"时:分:秒"<<hour<<":"<<minute<<":"<<sec<<endl;
}
class TimeDate:public Date,public Time
{
public:
TimeDate(int y=0,int m=0,int d=0,int h=0,int min=0,int s=0);
void show();
};
TimeDate::TimeDate(int y,int m,int d,int h,int min,int s):Date(y,m,d),Time(h,min,s){}
void TimeDate::show()
{
Date::printDate();
Time::printTime();
}
int main()
{
TimeDate t2(3013,5,23,9,30,0),t1;
t1.show();
t2.show();
t1.setDate(2013,05,24);
t1.printDate();
t1.setTime(15,20,15);
t1.printTime();
t1.show();
return 0;
}
运行结果: