下列程序的输出结果是 ( )
#include
using namespace std;
class A{
int a
public:
A():a(9){}
virtual void print() const {cout<};
class B:public A{
char b;
public:
B(){b= ‘S’;}
void print()const{cout<};
void show(Aa&X){X,print()}
int main()
{ Ad1;*p;
Bd2;
p=&d2;
d1,print();
d2,print();
p->print();
show(d1);
show(d2);
return 0;}
s--
第1题:
有以下程序: #include<iostream> using namespace std; class A { private: int x; public: A(int a) { x=a; } friend class B; }; class B { public: void print(A a) { a.x--; cout<<a, x<<end1; } }; int main () { A a(10); B b; b.print (a) ; return 0; } 程序执行后的输出结果是( )。
A.9
B.10
C.11
D.12
第2题:
下面程序的输出结果是【 】。
include <iostream>
using namespace std;
class A
{
int a, b;
public:
A()
{
a = b = 0;
}
A(int aa, int bb ) : a(aA) , b(bB)
{
cout <<"a="<<a<<","<<"b="<<b<<",";
}
~A()
{
cout<<"D";
};
int main ( )
{
A x, y(2, 3);
return 0;
}
第3题:
若有以下程序: #include <iostream> using namespace std; class A { protected: int a; public: A() { a=10; } }; class A1 : public A { public: A1() { a=a+1; } }; class A2 : public A { public: A2 () { a=a+2; } }; class B : public A1,public A2 { public: B(){} void print() { cout<<a<<end1; } }; int main ( ) { B obj; obj.print(); return 0; } 程序运行后的输出结果是( )。
A.产生语法错误
B.11
C.12
D.10
第4题:
如下程序的输出结果是 #include<iostream> using namespace std; class A{ public: A( ){cout<<"A";} }; class B{public:B( ){cout<<"B";}}; class C:public A{ B b; public: C( ){cout<<"C";} }; int main( ){C obj;return 0;}
A.CBA
B.BAC
C.ACB
D.ABC
第5题:
下面程序执行的结果是【 】
include<iostream>
using namespace std;
class A{
public:
static int x;
A(inty){cout<<x+y;}
};
int A::x=2;
void main(){
A a(5);
}
第6题:
下面程序的输出结果是( )。 #include <iostream> using namespace std; class A { public: A( ) {cout<<"A";} } class B { public: B() {coat<<"B" ;} } class C: public A { public: B b; C() {cout<<"C";} } void mian(){ C c; }
A.CBA
B.ABC
C.ACB
D.BCA