#include "stdio.h"
#include "iostream"//输入输出头文件
using namespace std;
//-------基类日期-----------//
class Date
{
public:
Date() {}//构造函数
Date(int y, int m, int d){ SetDate(y, m, d);}//带参数构造函数
void SetDate(int y, int m, int d)//设置日期的函数
{
Year = y;
Month = m;
Day = d;
cout<<"初始化日期了"<<endl;
}
void GetStringDate()//输出日期的函数
{
cout<<"Date:"<<endl;
cout<<Year<<"年"<<Month<<"月"<<Day<<"日"<<endl;
}
protected:
int Year, Month, Day;
};
//-------基类时间-----------//
class Time
{
public:
Time() {} //构造函数
Time(int h, int m, int s) { SetTime(h, m, s); } //带参数构造函数
void SetTime(int h, int m, int s)//设置时间的函数
{
Hours = h;
Minutes = m;
Seconds = s;
cout<<"初始化时间了"<<endl;
}
void GetStringTime() //输出时间的函数
{
cout<<"Time:"<<endl;
cout<<Hours<<"时"<<Minutes<<"分"<<Seconds<<"秒"<<endl;
}
protected:
int Hours, Minutes, Seconds;
};
//-------派生类 时间日期-----------//
class TimeDate:public Date, public Time
{
public:
TimeDate():Date() {} //构造函数
TimeDate(int y, int mo, int d, int h, int mi, int s):Date(y, mo, d), Time(h, mi, s) {}//带参数构造函数
void GetStringDT() //输出时间日期的函数
{
cout<<"TimeDate"<<endl;
cout<<Year<<"年"<<Month<<"月"<<Day<<"日"<<Hours<<"时"<<Minutes<<"分"<<Seconds<<"分"<<endl;
}
};
//-------main()函数入口----------//
int main(int argc, char* argv[])
{
TimeDate date1, date2(2008, 9, 10, 8, 30, 30);
date1.SetDate(2000,10,7);
date1.SetTime(12, 30, 00);
cout<<"The date1 date and time is :"<<endl;
date1.GetStringDT();
date1.GetStringDate();
date1.GetStringTime();
cout<<endl;
cout<<"The date2 date and time is:"<<endl;
date2.GetStringDT();
date2.GetStringDate();
date2.GetStringTime();
cout<<endl;
system("pause");
return 0;
}
#include "iostream"//输入输出头文件
using namespace std;
//-------基类日期-----------//
class Date
{
public:
Date() {}//构造函数
Date(int y, int m, int d){ SetDate(y, m, d);}//带参数构造函数
void SetDate(int y, int m, int d)//设置日期的函数
{
Year = y;
Month = m;
Day = d;
cout<<"初始化日期了"<<endl;
}
void GetStringDate()//输出日期的函数
{
cout<<"Date:"<<endl;
cout<<Year<<"年"<<Month<<"月"<<Day<<"日"<<endl;
}
protected:
int Year, Month, Day;
};
//-------基类时间-----------//
class Time
{
public:
Time() {} //构造函数
Time(int h, int m, int s) { SetTime(h, m, s); } //带参数构造函数
void SetTime(int h, int m, int s)//设置时间的函数
{
Hours = h;
Minutes = m;
Seconds = s;
cout<<"初始化时间了"<<endl;
}
void GetStringTime() //输出时间的函数
{
cout<<"Time:"<<endl;
cout<<Hours<<"时"<<Minutes<<"分"<<Seconds<<"秒"<<endl;
}
protected:
int Hours, Minutes, Seconds;
};
//-------派生类 时间日期-----------//
class TimeDate:public Date, public Time
{
public:
TimeDate():Date() {} //构造函数
TimeDate(int y, int mo, int d, int h, int mi, int s):Date(y, mo, d), Time(h, mi, s) {}//带参数构造函数
void GetStringDT() //输出时间日期的函数
{
cout<<"TimeDate"<<endl;
cout<<Year<<"年"<<Month<<"月"<<Day<<"日"<<Hours<<"时"<<Minutes<<"分"<<Seconds<<"分"<<endl;
}
};
//-------main()函数入口----------//
int main(int argc, char* argv[])
{
TimeDate date1, date2(2008, 9, 10, 8, 30, 30);
date1.SetDate(2000,10,7);
date1.SetTime(12, 30, 00);
cout<<"The date1 date and time is :"<<endl;
date1.GetStringDT();
date1.GetStringDate();
date1.GetStringTime();
cout<<endl;
cout<<"The date2 date and time is:"<<endl;
date2.GetStringDT();
date2.GetStringDate();
date2.GetStringTime();
cout<<endl;
system("pause");
return 0;
}