c++面向对象程序设计试题和答案(题目).docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《c++面向对象程序设计试题和答案(题目).docx》由会员分享,可在线阅读,更多相关《c++面向对象程序设计试题和答案(题目).docx(16页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、一、填空题(每空1分,共14分)1、观看以下程序:class pointpublic:pointvoid show() cout endl;);void main()(point pl;point *p;p=&p 1;pl.show ()通过对象pl访问show函数p.show ()通过指针p访问show函数)、在C+类中可以包含公共 、保护 和私有三种具有不同访2问控制权的成员。、定义类时,在类头中将使用关键3字class来表示类定义的开场。、如果一个类中至少有一个纯虚函数,那末该类称4为抽象类 o、C+类的组成包括数据成员和 成员函数,友元是(是、不 5是)该类的成员函数。6、友员函数是用
2、关键字 friend修饰的非成员函数。7、假设有:int i;int&j二i;i=10; j=i+l;那末 i=11, j=11o8、new的功能是分配内存空间 , delete的功能是 释放内存空间。word选择题(每题1.5分,二、共30分)1) 10D2、B 3、 C 4、D 5、 D 6、 B7、B 8、C 9、C、19A 11、D 12、C 13、D 14、B 15、C 16、A 17、B 18、C、C20、A三、改错题(每错2分,共6分)MyClass obj 1 (0);obj 1 .SetMember(5);obj2.SetMember( 10);5分,共20四、写出以下程序的
3、执行结果每题 分30 15分)2) ) 7 9(每一个 2.5 分)(每一个2.5 20 2。分)4)3 (2 分)3 (2 分)3 ( 1 分五、编程题每题10分、共 30分)第1。页#include #include class rectangle/(2 分)(private:intxl,yl,x2,y2;/(2 分)public:rectangle(int xxl,int yyl,int xx2,int yy2) /(l 分)(xl=xxl ;yl=yyl ;x2=xx2;y2=yy2;)int getarea()/(2 分)(return abs(x2-xl)*(yl-y2););vo
4、id main()(rectangle recti(3,7,8,5); (2 分)coutrectl .getarea()endl; (1 分)word2、(10 分)#include class car; ( 1 分)class boatprivate:int weight;/(l 分)public:boat(int w):weight(w)/(1分)friend int totalweight(boat bl,car cl);/(2 分);class car/(l 分)private:int weight; (1 分)public:car(int w):weight(w);friend i
5、nt totalweight(boat bl,car cl); (1 分);int totalweight(boat b 1 ,car c 1 )/(l 分)第12页return b 1. weight+c 1. weight;)void main()(car cl(1000);boat bl(2000);couttotalweight(bl,c 1 )endl;(l 分) )3、(1。分)#includeclass vehicle /(3定义汽车类分)protected:int wheels;/车轮数float weight; 分量public:vehicle(int wheels,floa
6、t weight); int get_wheels();wordfloat get_weight();float wheel_load(); void show();;定义小车类)class car:publicvehicle / int passenger_load;/载人数public:car(int wheels,float weight,int passengers=4);int get_passengers();void show();;vehicle: :vehicle(int wheels 1,float weight 1)/(1 分) (wheels二 wheels 1;wei
7、ght= weight 1;)int vehicle:get_wheels() return wheels;float vehicle: :get_weight()(return weight;)void vehicle:show()(l 分)(车轮个分量公斤)car:car(int wheels, float weight,int passengers) :vehicle(wheels, weight) (passenger_load=passengers;)int car: :get_passengers ()(return passenger_load;)void ca亡:show。wo
8、rd车型:小车vehicle:show ();载人人cout endl;)void main ()(car carl (4,2000,5);( 1 分)输出结果carl, show (); (1 分)婕统偌燃第雕,,海礴撇足髀下攀指需可飘修通改造补嘛,双达击到可加酬的除萩善眉页脚。谢谢!第16页二、选择题(每题1.5分,共30分)1、以下特性中不是面向对象程序设计语言所特有的是(D)。(A)数据封装(B)继承C)多态性D)模板1、 (B)是给变量取一个别名,它引入了变量的允许词。(A)指针B引用(C)枚举(D)构造3、类成员的访问权限中,只能被本类的成员函数和其友元函数访问。(A shareB
9、) publicC) privateD) protected4、关于构造函数,以下说法不正确的选项是U o(A构造函数名字和类名一样(B)构造函数在创立对象时自动执行(C)构造函数无任何函数返回类型(D构造函数有且惟独一个5、派生类可以访问其基类的。A )公有成员B)保护成员C)私有派生D)公有和保护成员6、以下关于运算符重载的描述中,错误的选项是U oA运算符重载不可以改变操作数的个数B运算符重载不可以改变运算符的功能运算符重载不可以改变结合方向D)运算符重载不可以改变运算优先级7、C+语言是从早期的C语言逐渐开展演变而来的.与C语言相比,它在求解问题方法上 发展的最大改良是A面向过程B)面
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c+ 面向 对象 程序设计 试题 答案 题目
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内