练习题综合 下载本文

内容发布更新时间 : 2024/5/22 16:21:46星期一 下面是文章的全部内容请认真阅读。

public:

virtual void f( ) { TWO::f( );

cout << \

void main( ) };

{

ONE aa, *p; TWO bb; THREE cc; p = &cc; p->f( );

写出执行该程序的输出结果。 }

参考答案: 2213

序号:115 难度:1 考查点:继承与派生

4.(分值:0.4 分)有如下程序: #include class TestClass1 { public:

TestClass1( ){cout<<\

};

class TestClass2 { public:

TestClass2( ){ cout<<\

};

class TestClass3:public TestClass1 {

TestClass2 b;

public:

TestClass3( ){ cout<<\

};

void main( ) {

TestClass3 obj;

}

写出该程序的执行后的输出结果。 参考答案: ABC

序号:116 难度:1 考查点:继承与派生

5.( 分值: 0.4 分 ) 有如下程序:

#include

class Con

{

ID;

public:

Con(){ID=′A′;cout<<1;}

char getID(){return cout<

ID;}

};

int Con c2(′B′);

main()

{

cout<

Con

char c1;

Con(char id){ID=id;cout<<2;}

return 0;

}

写出此程序的运行结果。

参考答案: 1A2B

序号:135 难度:1 考查点:类与对象

6.(分值:0.4 分)有如下程序:

#include

using namespace std;

class

Test

{public:

Test( ) { n+=2; }

~Test( ) { n-=3; }

static int getNum( )

{ return n; }

private:

static int n;};

int Test::n = 1;

int main( )

{Test* p = new Test;

delete p;

cout << \执行后的输出结 果是( )。

参考答案: n=3

序号:165 难度:2 考查点:类与对象

7.(分值:0.4分

#include

MyClass(){cout<using namespace std;

class )#include MyClass

{ public: ? AR? ;}

MyClass(char c {cout<{ MyClassp1,*p2 0; }

参考答案: AXBB

序号:166 难度:2 考查点:类与对象

~MyClass(){sout<

};

delete p2;

Int return

执行这个程序幕上将显示输出______。

8.(分值: 0 .4 分)有如下程序

#include

using namespace std; Base

{ c){cout<} 参考答案: AB

序号:167 难度:2 考查点:类与对象

protected; };

};

Base(){cout<

public:

class Derived:public Base{

int main()

{

class Base(char

Derived(char

Derived d1(R? BR? );

return 0;

执行这个程序屏幕上将显示输出______。

9.( 分 值 : 0.4 分 ) 分 析 以 下 程 序

#include

#include

class Sample

{ 执 行 的 结 果

int x,y;

void {

main()

{ 参考答案:

Sample(){x=y=0;} disp()

public:

cout<<\

}

};

void

Sample(int a,int b){x=a;y=b;}

Sample s1(2,3);

s1.disp();

}

x=2,y=3

序号:168 难度:2 考查点:类与对象

10.(分值:0.4 分)创建对象数组时,对数组的每一个元素都将调用一次构造函数,如果没有 显式给出数组元素的初值,则调用缺省构造函数,下列程序涉及到对象数组的创建和单个对 象的创建,其输出结果是

#include

using namespace std; Foo

{public:

Foo(int X){cout <Foo(){}

}; main()

{ Foo f[3],g(3);

return 0; }

参考答案: A

序号:169 难度:2 考查点:类与对象

class

int

11.(分值:0.4 分)阅读以下程序:

#include

using namespace std;

class

A

{

int a,b;

public:

A( );

A(int i, int j);

void

print( );

};

A::A( ) { a=5; b=10; }

A::A(int i, int j) { a=i,b=j; }

void A::print( )

{ cout<<\ }

void main( )

{

A a1, a2(15, 18);

a1.print( );

a2.print( );

}

写出程序运行后 a1.a 与 a2.b 的值。(答案格式:a1.a 空格 a2.b,例如:3 5)

参考答案: 5 18

序号:17 难度:1 考查点:类与对象

12.( 分 值 : 分 x,y; ) 分 析 以 下 程 序行 结果

#include

class Sample

{ 0.4 int

public: 的 执

Sample(){x=y=0;}

Sample(int a,int b){x=a;y=b;} cout<<\

void

{ main()

{ 参考答案: x=2,y=3 x!=y

序号:170 难度:2 考查点:类与对象

cout<<\

Sample s1(2,3);

s1.disp();

}

~Sample()

else

{

cout<<\

if(x==y)

} disp()

}

};

void

13.( 分 值 : 0.4 分 ) 分 析 以 下 程 序 的 输 出 结 果

#include

class Sample

{

{

object:x=\ obj(n);}

void main()

{ 参考答案:

counstructing object:x=1

序号:171 难度:2 考查点:类与对象

int x;

public:

Sample(int

cout<<\

static Sample

func(10);}

a)

x=a;

func(1);

}

};

void func(int n)

{

14.( 分 值 : 0.4 分 ) 分 析 以 下 程 序 的 执 行 结 果

#include

class Sample

{ int x,y;

public:

Sample(){x=y=0;}

Sample(int

{ main()

{ 参考答案: x=2,y=3

a,int b){x=a;y=b;}

cout<<\

p->disp();

}

void disp()

}

};

void

Sample s(2,3), *p=&s;

序号:172 难度:2 考查点:类与对象

15.( 分 值 : 0.4 分 ) 分 析 以 下 程 序 的 执 行 结 果

#include

class Sample

{

~Sample();

x;};

Sample::Sample()

{

normally\\n\ m)

{ number:\ main()

{ Sample obj1;

obj2.display();

}

参考答案:

constructing nomally

constructing with a number:20

display a number:0

display a number:20

destructing

destructing

序号:173 难度:2 考查点:类与对象

public:

Sample();

void display();

x=0; x=m;

protected:

Sample(int);

int

cout<<\

cout<<\ with a

cout<<\

a

Sample::display()

{

number:\

cout<<\

Sample obj2(20);

obj1.display();

16.( 分 值 : 0.4 分 ) 分 析 以 下 程 序 的 执 行 结 果

#include

class Sample

{ int n;

public:

Sample(int i){n=i;}

friend int

add(Sample &s1,Sample &s2);

};

int add(Sample &s1,Sample &s2)

{ return

s1.n+s2.n;}

void main()

{ Sample s1(10),s2(20);

cout< 参考答案: 30

序号:174 难度:2 考查点:类与对象

17.( 分 值 : 0.4 分 ) 写 出 此 题 的 运 行 结 果 :

#include

using namespace std;

class Complex

{

double re,im;

public:

Complex(double r,double i):re(r),im(i){ }

double real( )const{ return re; }

double )const{ return *this; }

};

ostream& operator<<(ostream& s,const Complex& image( z)

{ return im; }

Complex& operator+=( Complex )

{ re+=a.re;

im+=a.im;

return s<<''''(''''<int main( )

{ Complex x(1,2),y(2,3);

cout<<(x+=y)<return 0;}

参考答案: (3,5)

序号:175 难度:2 考查点:重载

18.( 分 值 : 0.4 )#include

class

分 a,int Sample

{

public:

Sample(){x=y=0;}

Sample(int b){x=a;y=b;}

~Sample()

{

if(x==y)

cout<<\

y\

disp()

{

cout<<\ main()

{

Sample s1(2,3);

s1.disp();

}

参考答案:

x=2,y=3

x!=y

序号:176 难度:2 考查点:重载

19.( 分 值 : 0.4 分 )#include

class

Sample

{

public:

Sample(){x=y=0;}

Sample(int a,int b){x=a;y=b;}

void disp()

{

cout<<\ main()

{

Sample s1,s2(2,3);

s1.disp();

s2.disp();

}

参考答案:

x=0,y=0

x=2,y=3

序号:177 难度:2 考查点:重载

20.( 分 值 : 0.4 分 )#include

class Sample

{

public:

Sample() {x=y=0;}

Sample(int a,int b)

{x=a;y=b;}

~Sample()

{

if(x==y)

cout<<\ \

disp()

{

cout<<\ main()

{

Sample s1,s2(2,3);

s1.disp();

s2.disp();

}

参考答案:

x=0,y=0

x=2,y=3

x!=y

x=y

序号:178 难度:2 考查点:重载

n)

{i=n;

cout<<\

setdata(double x)

{d=x;

21.(分值:0.4 分)#include

class Sample

{

public:

void setdata(int cout<<\ i;

double d;

};

void main()

{

Sample s;

s.setdata(10);

s.setdata(15.6);

}

参考答案:

i=10

d=15.6

序号:179 难度:2 考查点:重载

22.(分值:0.4 分)#include

class Sample

{

public:

Sample(){}

Sample(int i){n=i;}

Sample

&operator

=(Sample);

void

disp(){cout<<\Sample::n=s.n;

&Sample::operator=(Sample s)

{

main()

{

Sample s1(10),s2;

s2=s1;

s2.disp();

}

参考答案: n=10

序号:180 难度:2 考查点:重载

n;

};

Sample

return *this;

}

void

23.( 分 值 : 0.4 分 )#include

class Sample

{

public:

Sample(int i){n=i;}

operator++(){n++;}

operator++(int){n+=2;}

void disp()

{