更多"设有以下定义和程序: #include<iostream.h> cla"的相关试题:
[单项选择]设有以下定义和程序:
#include<iostream.h>
class A1
public:
void show1( )
cout<<"class A1"<<endl;
;
class A2:public A1
public:
void show2( )
cout<<"class A2"<<endl;
;
class A3:protected A2
public:
void show3( )
cout<<"class A1"<<endl;
;
void main( )
A1 obj1;
A2 obj2;
A3 obi3;
则以下不合语法的调用语句是( )。
A. objl.show1();
B. obj2.show1();
C. obj3.show1();
D. obj2.show2();
[单项选择]设有以下定义和程序:#include<iostream.h>class A1{public: void show1( ) { cout<<"class A1"<<endl; } };class A2 : public A1{public: void show2( ) { cout<<"class A2"<<end1 }};class A3 : protected A2{public: void show3( ) { cout<<"class A1"<<endl; }};void main( ){ A1 obj1; A2 obj2; A3 obj3;} 则以下不合语法的调用语句是
A. obj1. showl();
B. obj2. showl();
C. obj3. showl();
D. obj2. show2();
[单项选择]设有以下定义和程序:
#include <iostream.h>
class A1
public:
void showl( )
cout<<"class A1"<<end1;
;
Class A2 : public A1
public:
void show2( )
cout<<"Class A2"<<end1;
;
Class A3 : protected A2
public:
void show3( )
cout<<”Class A土”<<end1;
;
void main( )
A1 obj1;
A2 obj2;
A3 obj3;
则以下不合语法的调用语句是( )。
A. obj1.show1();
B. obj2.show1();
C. obj3.show1();
D. obj2.show2();
[单项选择]设有以下定义和程序:
#include<iostream.h>
class A1
public:
void show1( )
cout<<"class A1"<<end1;
;
class A2:public A1
public:
void show2( )
cout<<"class A2"<<end1;
;
class A3:protected A2
public:
void show3( )
cout<<"class A1"<<end1;
;
void main( )
A1 obj1;
A2 obj2;
A3 obj3;
则以下不合语法的调用语句是( )。
A. obj1.show1();
B. obj2.show1();
C. obj3.show1();
D. obj2.show2();
[单项选择]设有以下定义和程序: #include <iostream.h> class A1 { public: void showl( ) { cout<<"class A1"<<end1; } }; Class A2 : public A1 { public: void show2( ) { cout<<"Class A2"<<end1; } }; Class A3 : protected A2 { public: void show3( ) { cout<<”Class A土”<<end1; } }; void main( ) { A1 obj1; A2 obj2; A3 obj3; } 则以下不合语法的调用语句是( )。
A. obj1.show1();
B. obj2.show1();
C. obj3.show1();
D. obj2.show2();
[单项选择]设有以下定义和程序:
#include<iostream.h>
class TestClass1
public:
void show1( )
cout<<"TestClass1"<<end1;
;
class TestClass2:TestClass 1
public:
void show2( )
tout<<"TestClass2"<<end1;
;
class TestClass3:protected TestClass2
public:
void show3( )
tout<<"TestClass3"<<end1;
;
void main( )
TestClass1 obj1;
TestClass2 obj2;
TestClass3 obj3;
则以下不合语法的调用语句是( )。
A. obj1.show1();
B. obj2.show1();
C. obj3.show1();
D. obj2.show2();
[填空题]
[程序]
#include
#include
class B{
public:
B(char *s){name=new char[strlen(s)+1];strcpy(name,s);}
virtual void print( ){cout<<"姓名;"<
protected:
char *name;
};
class P1:public B{
public:
P1(char *s,float g):B(s){x=g;}
void print(int i)
{ cout<<"姓名:"<年薪:"<万元。 /n";}
private:
float x;
};
class P2:public B{
public:
P2(char *s,int n):B(s){ num=n;}
void print( ){cout<<"姓名;"<月工资:"<元。/n";}
private:
int num;
};
void main(void)
{
B *p;
B x("张明");
P1 y("王虎",4.2);
P2 z("李建国",5000);
p=&x;p->print( );
p=&y;p->print( );
y.print(1);
p=&z;p->print( );
}
执行以上程序后输出的第二行是() ,第四行是()。
[单项选择]下列程序的输出结果是
#include
class Myclass
public:Myclass(int i=0,intj=0)
x=i;
y=j;
void show( ) cout < < "x=" < < x < < " " < "y=" < < y < < end1;
void show( )const cout < < "x=" < < " " < < "y=’ < < y < < end1;
privated:
int x; int y;
;
void main( )
Myclass my1(3,4);
const my2(7,8);
my1.show( );my2.show( );
A. x=4,y=3;x=7,y=8
B. x=3,y=4;x=7,y=8
C. x=7,y=8;x=4,y=3
D. x=8,y=7;x=7,y=8
[单项选择]下列程序的输出结果是 #include class Myclass {
public:Myclass(int i=0,intj=0) { x=i;
y=j; } void show( ) { cout < < "x=" < < x
< < " " < "y=" < < y < < end1;} void show( )const { cout < < "x=" <
< " " < < "y=’ < < y < < end1;} privated:
int x; int y; }; void main(
) { Myclass my1(3,4); const my2(7,8);
my1.show( );my2.show( );}
A. x=4,y=3;x=7,y=8
B. x=3,y=4;x=7,y=8
C. x=7,y=8;x=4,y=3
D. x=8,y=7;x=7,y=8
[填空题]
[程序]
#include
class A{
public:
A(char *s){cout<
A( ){ };
};
class B:public A{ //L1
public:
B(char *s1,char *s2):A(s1)
{ cout<
};
class C : public A{ //L2
public:
C(char *s1,char *s2):A(s1)
{ cout<
};
class D:public B,public C{
public:
D(char *s1,char *s2,char *s3,char *s4):B(s1,s2),C(s1,s3)
{ cout<
};
void main(void)
{
D *ptr= new D("students","study","C++","hard");
delete ptr;
}
执行程序后共输出___(1)___行.
若分别将L1行改为;class B : virtual public A{ //L1
L2行改为:class C:virtual public A{ //L2
则执行程序后共输出___(2)___行。
[单项选择]下列程序执行结果是
#include <iostream.h>
class A
public:
int a;
A( ):a(10)cout<<a<<endl;
;
void main( )
A obj1;
A obj2(obj1);
cout<<" "<<obj2.a<<endl;
A. 10 10
B. 编译错误缺少拷贝构造函数
C. 10随机数
D. 随机数随机数
[单项选择]下面程序的输出结果是
#include<iostream.h>
class A
public:
A( ) cout < < "construtA" < < endl;
Virtual~A( ) cout < < "destructA" < < endl;;
class B: public A
;
class C:public A
;
class D:public B,public C
;
void main( )
D d;
A. constructA
B. constructA
C. constructA
D. constructA
[填空题]#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=new Bas( );
Dev p;
a=&p;
a->f( );
[填空题]以下程序的执行结果是______.
#include<<iostream.h>
c1ass A
public:
virtual void funl ( ) cout<<"A fun1"<<endl;
virtual void fun2 ( ) cout<<"A fun2"<<endl;
void fun3 ( ) cout<<" A fun 3 "<<endl:)
void fun4 ( ) cout<<" A fun4 "<<endl:
;
class B: public
public:
virtual void funl( ) cout<<" B funl"<<end1;
virtual void fun2 (int x) Cout<<"B fun2 "<<endl;
virtual void fun3( ) cout<<"B fun 3"<<endl;
void fun4( ) cout<<"B fun4"<<endl;
;
void main( )
A*p;
B b;
P=&b;
P->funl ( );
P->fun2( );
P->fun3( );
P->fun4( ):