首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2020-06-29
35
问题
请使用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://jikaoti.com/ti/yjA0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
A、 B、 C、 D、 D在软件开发的过程中,应该尽早的制定测试计划,其中在需求分析阶段制定系统测试计划,在概要设计阶段制定集成测试计划,在详细设计阶段制定单元测试计划。
有如下程序:#includeusingnamespacestd;intmain(){cout.fill(‘*’);cout.width(6);cout.fill(‘#’)
检查软件产品是否符合需求定义的过程称为
若要访问指针变量p所指向的数据,应使用表达式______。
将运算符*重载为类成员函数时,其参数表中有且仅有一个参数,说明该运算符是
下面描述中不属于软件需求分析阶段任务的是
下列数据结构中,能够按照“先进后出”原则存取数据的是()。
随机试题
A.黏血便,血呈鲜红色B.暗红色血便C.两者均有可能D.两者均不可能结肠癌的表现是
最可能是乳腺纤维腺瘤的是最可能是乳腺脓肿的是
A.砷B.氟C.钙D.磷E.硫氰酸盐促甲状腺肿物质是
A.士的宁B.小檗碱C.氧化苦参碱D.莨菪碱E.麻黄碱马钱子中所含的生物碱是()。
某依法必须进行招标的燃油锅炉采购项目,评标委员会经过初步审查,认为投标人A投标的锅炉与招标文件中要求的使用环境、参数、热效率等基本一致,但其价格过高,为此,招标人代表建议评标委员会进行了以下两项澄清,要求投标人A做进一步说明:(1)如果中标,在现
根据《大中型水利水电工程建设征地补偿和移民安置条例》的有关规定,移民经费列入( ),工程开工后,按批准的年度移民安置计划提前拨款。
下列属于计算机的性能指标的是()。
某企业生产甲、乙两种产品,运用品种法计算产品成本。直接材料、直接人工,制造费用均为甲、乙产品共同耗用,直接材料分产品领用。直接材料在生产开工时一次投人。有关资料如下:(1)甲产品期初在产品成本为3350元,其中,直接材料1600元,直接
公务员惩处的种类有()。
我国1982年宪法是在()基础上修改而成的。
最新回复
(
0
)