完整版c++面向对象程序设计试题和答案doc.docx

上传人:b****1 文档编号:1808228 上传时间:2023-05-01 格式:DOCX 页数:31 大小:20.80KB
下载 相关 举报
完整版c++面向对象程序设计试题和答案doc.docx_第1页
第1页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第2页
第2页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第3页
第3页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第4页
第4页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第5页
第5页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第6页
第6页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第7页
第7页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第8页
第8页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第9页
第9页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第10页
第10页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第11页
第11页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第12页
第12页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第13页
第13页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第14页
第14页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第15页
第15页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第16页
第16页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第17页
第17页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第18页
第18页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第19页
第19页 / 共31页
完整版c++面向对象程序设计试题和答案doc.docx_第20页
第20页 / 共31页
亲,该文档总共31页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

完整版c++面向对象程序设计试题和答案doc.docx

《完整版c++面向对象程序设计试题和答案doc.docx》由会员分享,可在线阅读,更多相关《完整版c++面向对象程序设计试题和答案doc.docx(31页珍藏版)》请在冰点文库上搜索。

完整版c++面向对象程序设计试题和答案doc.docx

完整版c++面向对象程序设计试题和答案doc

 

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_题

_

_

_答

_

_

名不

姓内

_

_

_线

_

_

_封

_

_

_密

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

一、填空题(每空1分,共14分)

 

1、观看以下程序:

classpoint{

public:

voidshow(){cout<<”point”<

};

voidmain()

{

pointp1;

point*p;

p=&p1;

_______________//通过对象p1访问show函数

______________//通过指针p访问show函数

}

2、在C++类中可以包含______________、______________和______________三种具有不

同访问控制权的成员。

3、定义类时,在类头中将使用关键字_____________来表示类定义的开始。

4、如果一个类中至少有一个纯虚函数,则该类称为________________。

5、C++类的组成包括数据成员和______________,友元_____(是、不是)该类的成员

函数。

6、友员函数是用关键字____________修饰的非成员函数。

7、若有:

inti;

int&j=i;

i=10;

j=i+1;

则i=__________,j=__________。

 

8、new的功能是____________________,delete的功能是

____________________。

 

二、选择题(每小题1.5分,共30分)

1、下列特性中不是面向对象程序设计语言所特有的是()。

(A)数据封装(B)继承(C)多态性(D)模板

2、()是给变量取一个别名,它引入了变量的同意词。

——第1页——

 

(A)指针(B)引用(C)枚举(D)结构

3、类成员的访问权限中,()只能被本类的成员函数和其友元函数访问。

(A)share(B)public(C)private(D)protected

4、关于构造函数,下列说法不正确的是()。

(A)构造函数名字和类名相同

(B)构造函数在创建对象时自动执行

(C)构造函数无任何函数返回类型

(D)构造函数有且只有一个

5、派生类可以访问其基类的()。

(A)公有成员(B)保护成员

(C)私有派生(D)公有和保护成员

6、下列关于运算符重载的描述中,错误的是()。

(A)运算符重载不可以改变操作数的个数

(B)运算符重载不可以改变运算符的功能

(C)运算符重载不可以改变结合方向

(D)运算符重载不可以改变运算优先级

7、C++语言是从早期的C语言逐渐发展演变而来的.与C语言相比,它在求解问题方法上

进行的最大改进是()

(A)面向过程(B)面向对象(C)安全性(D)复用性

8、对于类中定义的成员,其隐含访问权限为()。

A.publicB.protected

C.privateD.static

9、下面有关重载函数的说法中正确的是()

(A)重载函数必须具有不同的返回值类型;(B)重载函数形参个数必须不同;

(C)重载函数必须有不同的形参列表(D)重载函数名可以不同;

10、有如下的对类“CSample”的说明,其中()是错误的。

classCSample{

A.inta=23;

B.CSample();

public:

C.CSample(intval);

D.~CSample();

11、在inta=3,int*p=&a;中,*p的值是()

A.变量a的地址值B.无意义

C.变量p的地址值D.3

12、每个类()构造函数。

(A)只能有一个(B)只可有公有的

 

——第2页——

 

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_题

_

_

_答

_

_

名不

姓内

_

_

_线

_

_

_封

_

_

_密

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

(C)可以有多个(D)只可有缺省的

 

13、在一个类中可以对一个操作符进行()重载。

(A)1种(B)2种以下(C)3种以下(D)多种

14、在公有继承的情况下,基类非私有成员在派生类中的访问权限()

(A)受限制(B)保持不变(C)受保护(D)不受保护

15、应在下列程序划线处填入的正确语句是()

#include

classBase

{public:

voidfun(){cout<<"Base:

:

fun"<

};

classDerived:

publicBase

{voidfun()

{_____________//显示调用基类的函数fun()

cout<<"Derived:

:

fun"<

}

};

(A)fun();(B)Base.fun();(C)Base:

:

fun();(D)Base->fun();

16、执行下面的程序将输出()

#include

classBASE{

charc;

public:

BASE(charn):

c(n){}

virtual~BASE(){cout<

};

classDERIVED:

publicBASE{

charc;

public:

DERIVED(charn):

BASE(n+1),c(n){}

~DERIVED(){cout<

};

intmain()

{DERIVEDa('X');

 

——第3页——

 

return0;

}

(A)XY(B)YX(C)X(D)Y

17、下面描述中,表达错误的是()

(A)公有继承时基类中的public成员在派生类中仍是public的

(B)公有继承是基类中的private成员在派生类中仍是private的

(C)公有继承时基类中的protected成员在派生类中仍是protected的

(D)私有继承时基类中的public成员在派生类中是private的

18、定义析构函数时,应该注意()

(A)其名与类名完全相同(B)返回类型是void类型

(C)无形参,也不可重载(D)函数体中必须有delete语句

19、对于在类中定义的静态数据成员,下面正确的说法是()

A.该类的每个对象中都有一个静态数据成员

B.对象创建时产生

C.在类外进行初始化

D.既可以在类外初始化,也可以在类内初始化

 

20、C++中声明常量的关键字是()。

A.constB.externC.publicD.enum

 

三、改错题(每处2分,共6分)

1、使用VC6打开考生文件夹下的工程proj1,此工程包含一个源程序文件main.cpp,但

该程序运行有问题,请改正main函数中的错误,使程序的输出结果为:

member=0

member=5

menber=10

源程序文件main.cpp清单如下:

#include

classMyClass

{

public:

MyClass(inti){member=i;}

voidSetMember(intm){member=m;}

intGetMember()const{returnmenber;}

voidprint()cont{cout<<"member="<

private:

 

——第4页——

 

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_题

_

_

_答

_

_

名不

姓内

_

_

_线

_

_

_封

_

_

_密

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

intmember;

 

};

voedmain()

{

MyClassobj1;//更正_____________________________

obj1.print();

MyClassobj2(3);

obj1.member=5;//更正__________________________

MyClass.SetMember(10);//更正_______________________

obj1.print();

obj2.print();

}

 

四、写出下列程序的执行结果(每小题

5分,共20分)

1、

#include

classSample

{intn;public:

Sample(inti){n=i;}

friendintadd(Sample&s1,Sample&s2);

};

intadd(Sample&s1,Sample&s2)

{

returns1.n+s2.n;

}

voidmain()

{

Samples1(10),s2(20);

cout<

}

执行结果是:

 

2、

 

——第5页——

 

#include

intadd(intx,inty)

{

returnx+y+1;

}

doubleadd(doublex,doubley)

{

returnx+y-1;

}

voidmain()

{

inta=2,b=4;

doublec=2.6,d=7.4;

cout<

}

执行结果是:

 

3、

#include

classA

{

public:

intn;

};

classB:

virtualpublicA{};

classC:

virtualpublicA{};

classD:

publicB,publicC

{

intgetn(){returnB:

:

n;}

};

voidmain()

{

Dd;

 

——第6页——

 

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_题

_

_

_答

_

_

名不

姓内

_

_

_线

_

_

_封

_

_

_密

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

d.B:

:

n=10;

 

d.C:

:

n=20;

cout<

:

n<<","<

:

n<

}

执行结果是:

 

4、

 

#include

 

classmyclass

{

inta,b;

staticints;

public:

myclass(intx,inty)

{a=x;b=y;s++;}

voidprint()

{cout<

};

intmyclass:

:

s=0;

voidmain()

{

myclassm1(1,2),m2(4,5),m3(6,7);

m1.print();

m2.print();

m3.print();

}

 

执行结果是:

 

五、编程题(每题10分、共30分)

1、测试一个名为rectangle的矩形类,其属性为矩形的左下角与右上角两个点的坐标,

能计算矩形的面积。

(10分)

2、定义一boat与car两个类,二者都有weight属性,定义二者的一个友元函数

totalweight(),计算二者的重量和。

(10分)

 

——第7页——

 

3、设计一个汽车类vehicle,包含的数据成员有车轮个数wheels和车重weight。

小车

类car是它的派生类,其中包含载人数passenger_load。

每个类都有相关数据的输

出方法。

在主程序中定义一个car类对象,对其车轮个数、车重、载人数进行设置并显示。

(10分)

 

一、填空题(每空1分,共14分)

(1)p1.show();p->show()

(2)公有、私有、保护(3)class(4)抽象类

(5)成员函数、不是(6)friend(7)11、11(8)动态申请内存空间、释放

由new申请的空间

 

二、

选择题(每小题1.5分,共30

分)

1、D

2、B

3、C

4、D

5、D

6、B

7、B

8、C

9、C

10、A

11、D

12、C

13、D

14、B

15、C

16、A

17、B

18、C

19、C

20、

A

三、

改错题(每错2分,共6分)

MyClassobj1(0);

obj1.SetMember(5);

obj2.SetMember(10);

四、写出下列程序的执行结果

(每小题

5分,共20分)

(1)30

(5分)

(2)7

9(每个2.5

分)

(3)20

20

(每个2.5分)

(4)

3(2分)

3(2分)

3(1分)

五、

编程题(每题10分、共30分)

1、

#include

#include

——第8页——

 

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_题

_

_

_答

_

_

名不

姓内

_

_

_线

_

_

_封

_

_

_密

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

classrectangle//(2分)

 

{

private:

intx1,y1,x2,y2;//(2分)

public:

rectangle(intxx1,intyy1,intxx2,intyy2)//(1分)

{

x1=xx1;y1=yy1;x2=xx2;y2=yy2;

}

intgetarea()//(2分)

{

returnabs((x2-x1)*(y1-y2));

}

};

voidmain()

{

rectanglerect1(3,7,8,5);(2分)

cout<

}

 

2、(10分)

#include

classcar;(1分)

classboat{

private:

intweight;//(1分)

public:

boat(intw):

weight(w){}//(1分)

friendinttotalweight(boatb1,carc1);//(2分)

};

classcar{/(1分)

private:

intweight;(1分)

public:

car(intw):

weight(w){};

friendinttotalweight(boatb1,carc1);(1分)

};

inttotalweight(boatb1,carc1)//(1分)

{

returnb1.weight+c1.weight;

——第9页——

 

}

voidmain()

{

carc1(1000);

boatb1(2000);

cout<

}

 

3、(10分)

#include

classvehicle//定义汽车类(3分)

{

protected:

intwheels;//车轮数

floatweight;//重量

public:

vehicle(intwheels,floatweight);

intget_wheels();

floatget_weight();

floatwheel_load();

voidshow();

};

classcar:

publicvehicle//定义小车类(3分)

{

intpassenger_load;//载人数

public:

car(intwheels,floatweight,intpassengers=4);

intget_passengers();

voidshow();

};

vehicle:

:

vehicle(intwheels1,floatweight1)//(1分)

{

wheels=wheels1;

weight=weight1;

}

intvehicle:

:

get_wheels()

{

returnwheels;

}

floatvehicle:

:

get_weight()

——第10页——

 

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_题

_

_

_答

_

_

名不

姓内

_

_

_线

_

_

_封

_

_

_密

_

_

_

_

_

_

_

_

_

_

_

_

_

_

_

{

 

returnweight;

}

voidvehicle:

:

show()

(1分)

{

cout<<"车轮:

"<

cout<<"重量:

"<

}

car:

:

car(intwheels,floatweight,

intpassengers):

vehicle(wheels,weight)

{

passenger_load=passengers;

}

intcar:

:

get_passengers()

{

returnpassenger_load;

}

voidcar:

:

show()

{

cout<<"车型:

小车"<

vehicle:

:

show();

cout<<"载人:

"<

}

voidmain()

{

carcar1(4,2000,5);(1分)

cout<<"输出结果"<

car1.show();(1分)

}

 

——第11页——

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2