c++题…… 多谢!
给出下列程序的运行输出结果1、#include<iostream.h>classCPoint{public:CPoint(){X=Y=0;cout<<”缺省构造(”<<X...
给出下列程序的运行输出结果
1、
#include <iostream.h>
class CPoint
{ public:
CPoint ()
{ X=Y=0; cout<<”缺省构造(”<<X<<”,”<<Y<<”)\n”; }
CPoint (int x0, int y0)
{ X=x0;Y=y0; cout<<”构造(”<<X<<”,”<<Y<<”)\n”; }
~ CPoint(){ cout<<”析构(”<<X<<”,”<<Y<<”)\n”; }
private:
int X,Y;
};
void main()
{ CPoint p1(3,4),p2; }
2、
#include <iostream.h>
class Base
{public:
Base(){cout<<"Base"<<endl;}
};
class Level1: virtual public Base
{public:
Level1(){cout<<"Level1"<<endl;}
};
class Level2: virtual public Base
{public:
Level2(){cout<<"Level2"<<endl;}
};
class Toplevel: public Level1, public Level2
{public:
Toplevel(){cout<<"TopLevel"<<endl;}
};
void main(){ Toplevel t; }:
3.
class B1
{ public:
B1(int i) {cout<<"constructing B1 "<<i<<endl;}
~B1() {cout<<"destructing B1 "<<endl;}
};
class B2
{public:
B2(int j) {cout<<"constructing B2 "<<j<<endl;}
~B2() {cout<<"destructing B2 "<<endl;}
};
class B3
{public:
B3(){cout<<"constructing B3 *"<<endl;}
~B3() {cout<<"destructing B3 "<<endl;}
};
class C: public B2, public B1, public B3
{public:
C(int a, int b, int c, int d):
B1(a),memberB2(d),memberB1(c),B2(b){}
private:
B1 memberB1;
B2 memberB2;
B3 memberB3;
};
void main()
{ C obj(1,2,3,4); } 展开
1、
#include <iostream.h>
class CPoint
{ public:
CPoint ()
{ X=Y=0; cout<<”缺省构造(”<<X<<”,”<<Y<<”)\n”; }
CPoint (int x0, int y0)
{ X=x0;Y=y0; cout<<”构造(”<<X<<”,”<<Y<<”)\n”; }
~ CPoint(){ cout<<”析构(”<<X<<”,”<<Y<<”)\n”; }
private:
int X,Y;
};
void main()
{ CPoint p1(3,4),p2; }
2、
#include <iostream.h>
class Base
{public:
Base(){cout<<"Base"<<endl;}
};
class Level1: virtual public Base
{public:
Level1(){cout<<"Level1"<<endl;}
};
class Level2: virtual public Base
{public:
Level2(){cout<<"Level2"<<endl;}
};
class Toplevel: public Level1, public Level2
{public:
Toplevel(){cout<<"TopLevel"<<endl;}
};
void main(){ Toplevel t; }:
3.
class B1
{ public:
B1(int i) {cout<<"constructing B1 "<<i<<endl;}
~B1() {cout<<"destructing B1 "<<endl;}
};
class B2
{public:
B2(int j) {cout<<"constructing B2 "<<j<<endl;}
~B2() {cout<<"destructing B2 "<<endl;}
};
class B3
{public:
B3(){cout<<"constructing B3 *"<<endl;}
~B3() {cout<<"destructing B3 "<<endl;}
};
class C: public B2, public B1, public B3
{public:
C(int a, int b, int c, int d):
B1(a),memberB2(d),memberB1(c),B2(b){}
private:
B1 memberB1;
B2 memberB2;
B3 memberB3;
};
void main()
{ C obj(1,2,3,4); } 展开
1个回答
2011-12-19
展开全部
1.构造(3,4);
默认构造(0,0)
析构(0,0)
析构(3,4)
2.Level1
Level2
TopLevel
3.constructing B2 2
constructing B1 2
constructing B3 *
constructing B1 4
constructing B2 3
constructing B3 *
第一题我觉得你的析构函数有问题!我这台机子没有安装C++没有运行,建议你以后自己运行看结果最准确
默认构造(0,0)
析构(0,0)
析构(3,4)
2.Level1
Level2
TopLevel
3.constructing B2 2
constructing B1 2
constructing B3 *
constructing B1 4
constructing B2 3
constructing B3 *
第一题我觉得你的析构函数有问题!我这台机子没有安装C++没有运行,建议你以后自己运行看结果最准确
追问
2、3答案不对
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询