下面程序的结果是( )。 #include<iostream.h> class A int a; public:
A: A():a(1)
B: void showa()cout<<a;
C: ;
D: Class Bint a;
E: public:
F: B():a(2)
G: void showa()cout<<a;
H: );
I: class C:public A,public Bint a;
J: public:
K: C():a(3)
L: void showa()cout<<a;
M: ;
N: void main()C c;
O: c.showa();
P: A) 1
Q: B) 2
R: C) 3
S: D) 程序有错误
A: A():a(1)
B: void showa()cout<<a;
C: ;
D: Class Bint a;
E: public:
F: B():a(2)
G: void showa()cout<<a;
H: );
I: class C:public A,public Bint a;
J: public:
K: C():a(3)
L: void showa()cout<<a;
M: ;
N: void main()C c;
O: c.showa();
P: A) 1
Q: B) 2
R: C) 3
S: D) 程序有错误
举一反三
- 下面程序的结果是 #include<iostream.h> class A public: A( ) cout < < "construtA" < < end1; virtual ~A( ) cout < < "destructA" < < end1; ; class B:public A ; class C:public A ; class D:public B,public C ; void main( ) Dd; A: constructA B: destructA C: constructA D: constructA E: destructA F: destructA G: constructA H: constructA I: constructA J: destructA K: destructA L: destructA M: constructA N: constructA O: constructA P: constructA Q: destructA R: destructA S: destructA T: destructA
- 有如下程序: #include<iostream> using namespace std; class A public: virtual void func1()cout<<"A1"; void func2()cout<<"A2"; ; class B:public A public: void func1()cout<<"B1"; void func2()cout<<"B2"; ; int main() A: A*p=new B; B: p->func1(); C: p->func2(); D: delete p; E: retum 0;执行这个程序的输出结果是______。A.B1B2 F: A1A2 G: B1A2 H: A1B2
- 有如下程序: #include <iostream> using namespace std; class A public: A: A(int i)X=i; B: void dispa( )cout<<x<<','; C: private: D: int x; E: ; F: class B:public A G: public: H: B(int i):A(i+10)x=i; I: void dispb( )dispa( );cout<<x<<endl; J: private: K: int x; L: ; M: int main( ) N: B b(2); O: b.dispb( ); P: return 0; Q: 程序的输出结果是 A) 10,2 R: B) 12,10 S: C) 12,2 T: D) 2,2
- 写出程序运行结果:_________ #include <iostream.h> class Bas { public: ~Bas() { cout<<"Bas construct"<<endl; } virtual void f()=0; }; class Dev:public Bas { public: ~Dev() { cout<<"Bas construct"<<endl; } virtual void f() { cout<<"Dev::f"<<endl; } }; void main() { Bas *a; Dev p; a=&p; a->f(); }
- 设有以下定义和程序: #include<iostream.h> class A1 public: void show 1() cout<<" class A 1"<<end1; class A2:public A1 public: void show20 cout<<"class A2"<<end1; ; class A3:protected A2 public: void show3() cout<<"class A 1 "<<end1; ; void main() A: A1 obj1;A2 obj2;A3 obj3;则以下不合语法的调用语句是( B: )。A) obj1.show1(); C: B) obj2.show1(); D: C) obj3.show1(); E: D) obj2.show2();