( 10 )有如下程序:
#include<iostream>
using namespace std;
class A{
public:
A(){cout<<"A" ; }
~A(){cout<<"A" ; }
} ;
class B {
A a;
public:
B(){cout<<"B";}
~B(){cout<<"B";}
};
int main (){
B b;
return 0;
}
程序的输出结果是 ___________
第1题:
请将如下程序补充完整,使得输出结果为:bbaa。
include<iostream>
using naluespace std;
class A{
public:
______{eout<<"aa";}
};
class B:public A{
public:
~B( ){eont<<"bb";}
};
int ulain( ){
B*P=new B;
delete P;
return 0;
}
第2题:
若有以下程序: #include<iostream> using namespace.std; class data { public: int x; data (int x) { data::x=x; } ); class A { private: data d1; public: A(int x) :dl(X){} void dispa() { cout<<dl.X<<","; } }; class B:public A { private: data d2; public: B(int x) : A(x-1),d2(x){} void dispb() { cout<<d2.x<<endl; } }; class C:public B { public: C(int x) :B(x-1){} void disp() { dispa(); dispb(); } }; int main() { C obj(5); obj.disp(); return 0; } 程序执行后的输出结果是
A.5,5
B.4,5
C.3,4
D.4,3
第3题:
第4题:
有以下程序: #include <iostream> using namespace std; class A { private: iht a; public: A(int i) { a=i; } void disp() { cout<<a<<","; class B { private: int b; public: B(int j) { b-j; } void disp() { cout<<b<<","; } }; class C: public B,public A private: int c; public: C(int k):A(k-2),B(k+2) c=k; } void disp() { A::disp(); B::disp(); cout<<c<<endl; } }, int main() C obj(l0); obj.disp(); return 0; 程序执行后的输出结果是
A.10,10,10
B.10,12,14
C.8,10,12
D.8,12,10
第5题: