首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2020-05-14
73
问题
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
class vehicle
{
private:
int MaxSpeed;
int Weight;
pubhc:
//**********found**********
vehicle(int maxspeed,int weight):________
~vehicle(){};
int getMaxSpeed(){return MaxSpeed;}
int getWeight(){retum Weight;}
};
//**********found**********
class bicycle:——public vehicle
{
private:
int Height;
public:
bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){}
int getHeight(){return Height;};
};
//**********found**********
class motorcar:_________public vehicle
{
private:,
int SeatNum:
public:
motorear(int maxspeed,int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum){}
int getSeatNum(){return SeatNum;};
};
//**********found**********
class motorcycle:_________
{
public:
motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,height), motorcar(maxspeed,weight,1){}
};
void main()
{
motorcycle a(80,150,100);
cout<
cout<
cout<
cout<
}
选项
答案
(1)MaxSpeed(maxspeed),Weight(weight){}; (2)virtual (3)virtual (4)public bicycle,public motorcar
解析
(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员MaxSpeed和Weight初始化。
(2)主要考查考生对派生类的掌握,题目要求将vehicle作为虚基类,避免二义性问题。因此在这里添加virtual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorcar和bicycle作为基类,再派生出Inotorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bicyck,public motorcaro
转载请注明原文地址:https://kaotiyun.com/show/nM8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
执行语句for(i=1++<4;);,后变量i的值是
下列代码段声明了3个类:classPerson();classStudent:publicPerson{};classUndergraduate:Student{};下列关于这些类之间关系的描述中,错误的是()。
若要在程序文件中进行标准输入输出操作,则必须在开始的# include命令中使用头文件【 】。
关于二进制文件说法错误的是______。
“图形”类Shape中定义了纯虚函数CalArea(),“三角形”类Triangle继承了类Shape,请将Triangle类中的CalArea函数补充完整。classShape{public:virtualintCalArea()=0;}
若要访问指针变量p所指向的数据,应使用表达式______。
已知类A中有公用数据成员B *b;其中B为类名。则下列语句错误的是
下面有关纯虚函数的表述中正确的是()。
在C++中,动态创建对象可以使用【 】操作符来完成。
如果表达式x=y*z中的“*”是作为成员函数重的运算符,采用运算符函数调用格式,该表达式还可以表示为______。
随机试题
X2检验
Wefindthatbrightchildrenarerarelyheldbackbymixed-abilityteaching.Onthecontrary,boththeirknowledgeandexperienc
经营收入包括()。
不按国家规定的要求另设会计账簿进行核算的,对()可以处3000元以上5万元以下的罚款。
2017年1月1日,长江公司向黄河公司销售一批商品共3万件,每件售价100元,每件成本80元。销售合同约定2017年3月31日前出现质量问题的商品可以退回。长江公司销售当日预计该批商品退货率为12%。2017年1月31日,甲公司根据最新情况重新统计商品退货
中国共产党把毛泽东思想确定为党的指导思想的会议是()。
货源标记是用来表示()。
8,11,16,(),32
中国共产党在抗日民族统一战线中的策略总方针是()
WhichofthefollowingdetailsisINCORRECT?
最新回复
(
0
)