首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2020-06-29
31
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
1 #include
2 class vehicle
3 {
4 private:
5 int MaxSpeed;
6 int Weight;
7 public:
8 //**********found**********
9 vehicle (int maxspeed, int weight):_____
10 ~vehicle(){};
11 int getMaxSpeed(){return Max-Speed;}
12 int getWeight(){return Weight;}
13 };
14 //**********found**********
15 class bicycle:______public vehicle
16 {
17 private:
18 int Height;
19 public:
20 bicycle(int maxspeed,int weight,int height): vehicle {maxspeed,weight),Height(height){}
21 int getHeight(){return Height;};
22 };
23 //**********found**********
24 class motorcar:_______public ve-hicle
25 {
26 private:
27 int SeatNum;
28 public:
29 motorcar(int maxspeed,int weight,int seatnum):vehicle (maxspeed,weight),SeatNum(seatnum){}
30 int getSeatNum(){return SeatNum;};
31 };
32 //**********found**********
33 class motorcycle:_______
34 {
35 public:
36 motorcycle(int maxspeed, int weight,int height):vehicle(max speed,weight),bicycle(maxspeed, weight,height),motorcar(maxspeed, weight,1){}
37 };
38 void main()
39 {
40 motorcycle a(8 0,150,100);
41 cout<
42 cout<
43 cout<
44 cout<
45 }
选项
答案
(1)MaxSpeed(maxspeed),Weight(weight){}; (2)virtual (3)virtual (4)public bicycle,public motorcar
解析
(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员MaxSpeed和Weight初始化。
(2)主要考查考生对派生类的掌握,题目要求将vehicle作为虚基类,避免二义性问题。因此在这里添加virtual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorcar和bicycle作为基类,再派生出motorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getSeat-Num函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motoroarc,
转载请注明原文地址:https://kaotiyun.com/show/Gi8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
【】使一个函数可以定义成对许多不同数据类型完成同一个任务。
在下列关系运算中,可能改变关系中属性个数的是
关系数据库的关系演算语言是以【】为基础的DML语言。
有如下程序:#include<iostream>usingnamespacestd;classx{protected:inta;public:x(){a=1;}
以下有关成员函数特征的叙述不正确的是
为了使类中的某个成员不能被类的对象通过成员操作符访问,则不能把该成员的访问权限定义为
多继承的构造顺序可分为如下四步:①所有非虚基类的构造函数按照它们被继承的顺序构造②所有虚基类的构造函数按照它们被继承的顺序构造③所有子对象的构造函数按照它们声明的顺序构造④派生类自己的构造函数体这四个步骤
下列关于C++运算符结合性的说法中,正确的是()。
使用VC6打开考生文件夹下的源程序文件3.cpp,其中定义了类A、A1和A2,其中A1类由A类公有派生,A2类由A1类公有派生。(1)定义类A的构造函数,该构造函数有一个整型的参数x,在构造函数中请将x赋值给数据成员a。请在注释“//******
已知TV是一个类,并有函数func定义如下:voidfunc(){TVli,*net[2],company[3];}则在调用func()后,TV类的析构函数被调用的次数是
随机试题
硼砂是治疗口腔炎中成药冰硼散的主要成分,其分子式为()。
A.肝的疏泄功能B.肝的藏血功能C.两者均有关D.两者均无关
结核病患者膳食中优质蛋白质应占蛋白质总量的比例为
注册会计师可以在期中或期末实施控制测试或实质性程序,当重大错报风险较高时,注册会计师应当考虑在期末或接近期末实施实质性程序,或采用不通知的方式,或在管理层不能预见的时间实施审计程序。( )如果已识别出由于舞弊导致的重大错报风险,注册会计师应当考虑在期
为扩大市场份额,经股东大会批准,甲公司2×16年和2×17年实施了并购和其他有关交易。(1)并购前,甲公司与相关公司之间的关系如下:①A公司从2×13年1月1日起至今一直直接持有B公司30%的股权,同时受托行使其他股东所持有B公司18%股权的表决权。B
保健食品广告中必须说明的有()。
人体长时间剧烈运动时会产生大量酸性物质,血液中可以起到缓冲作用的物质是()。
简述我国宪法关于立法权和法律、法规制定、修改权的规定。
《沉香屑.第一炉香》《倾城之恋》都是中国著名现代小说家()的代表作品。
用SQL语句将STUDENT表中字段“年龄”的值加1,可以使用的命令是
最新回复
(
0
)