河南成教 / 面向对象程序设计
2[应用题]
#include
class Cdate
{
int day,month,year;
public:
Cdate ()
{
day=1;
month=1;
year=1999;
cout<<"default constructing
";}
Cdate (int d,int m,int y)
{
day=d;
month=m;
year=y;
cout<<"constructing
";
}
~ Cdate (){cout<<"destructing"<<><"><><><>
void print( )
{cout<<><">
<><>};
void main()
{ Cdate a1,*a2;
a2=new Cdate (30,12,1996);
a1.print();
a2->print();
delete a2;
}
运行结果是:
<"><">
2[应用题]
#include
class Cdate
{
int day,month,year;
public:
Cdate ()
{
day=1;
month=1;
year=1999;
cout<<"default constructing
";}
Cdate (int d,int m,int y)
{
day=d;
month=m;
year=y;
cout<<"constructing
";
}
~ Cdate (){cout<<"destructing"<<><"><><><>
void print( )
{cout<<><">
<><>};
void main()
{ Cdate a1,*a2;
a2=new Cdate (30,12,1996);
a1.print();
a2->print();
delete a2;
}
运行结果是:
<"><">
参考答案:
佳题速递: