第1个回答 推荐于2017-12-15
#include <iostream.h>
class CTime
{
public:
CTime(int a1,int b1,int c1)
{
a=a1;
b=b1;
c=c1;
}
void Print()
{
cout<<a<<":"<<b<<":"<<c<<endl;
}
int a,b,c;
};
class CDate:public CTime //类、继承
{
public:
CDate(int ,int ,int,int ,int ,int); //构造函数
~CDate(); //析构函数
CDate fun(const CDate & d); //const、拷贝构造函数
void Display();
private:
int year,month,day;
};
CDate::CDate (int y,int m,int d,int a1,int b1,int c1):CTime(a1,b1,c1)
{
year=y;
month=m;
day=d;
}
CDate::~CDate()
{
cout<<"析构!"<<endl;
}
void CDate::Display()
{
cout<<year<<"—"<<month<<"—"<<day<<"\t";
Print();
}
CDate CDate::fun(const CDate & d)
{
CDate d1(d.year,d.month,d.day,d.a,d.b,d.c);
return d1;
}
void main()
{
int a,b,c,d,e,f;
cout<<"请输入年、月、日:";
cin>>a>>b>>c;
cout<<"请输入时、分、秒:";
cin>>d>>e>>f;
CDate D1(a,b,c,d,e,f); //对象
D1.Display();
cout<<"**************"<<endl;
CDate D2=D1.fun(D1);
D2.Display();
cout<<"**************"<<endl;
CDate *p=&D1; //指针
p->Display();
}本回答被网友采纳