首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicyele作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicyele作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2017-07-04
47
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicyele作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
clasS vehicle
{
private:
int MaxSpeed;
int Weight;
public:
//**********found**********
vehicle (int maxspeed, int
weight):_______
一vehicle(){);
int getMaxSpeed() { return Max—
Speed;)
int getWeight(){return 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:
motorcar(int maxspeed,int weight
int seatnum):vehicle (maxspeed
weight),SeatNum(seatnum)f)
int getSeatNum(){return SeatNum;);
};
//********** found**********
class motorcycle :________
{
public:
motorcycle (int maxspeed, in
weight,int height):vehicle(ma,
speed,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作为基类,再派生出motorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeig}lt函数和getSeat—Num函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。
转载请注明原文地址:https://kaotiyun.com/show/JLAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
设有语句 int n,m; char a[5],b; cin>>n>>a>>m>>b; 为了分别将10和20分别赋给n和m,look赋给a,t赋给b,则正确的输入为
阅读以下程序 #includc<iostream.h> vold main() { Char line[10]; cin>>line; cout<<line<<endl; } 如运行时输入This is ex
下面程序段的正确输出是 int w=4,x=3,y=2,z=1; cout<<(w<x? w:z<y? z:x)<<endl;
假定变量m定义为int m=7;则定义变量p的正确语句为( )。
属于关系的基本类型的是( )。
设一棵二叉树的中序遍历结果为ABCDEFG,前序遍历结果为DBACFEG,则后序遍历结果为【 】。
以下不能够读入空格字符的语句是
在下列关系运算中,可能改变关系中属性个数的是
下列运算符中,*运算符在C++中不能重载()。
下列运算符中,不能重载的是
随机试题
A.出生率提高B.平均期望寿命提高C.劳动力的工作时间延长D.人均摄人的热量增加E.儿童肥胖率提高人群健康水平的提高有利于
下述有关募穴的概念哪项是错误的
短期用地和临时用地最适合采用()方式。
保护管管径的选择根据导线或电缆的外径计算,管内充填系数取( )左右。
下列关于纯风险的表述中,正确的有()。
在闭卷考试时,小明看到题目后首先在头脑中呈现出了问题的答案,他的这种心理活动属于()
管子是汉代由()传入我国中原地区的。
与音乐教育相互渗透的功能是()。
Overtheyears,I’veheardafairnumberofslursshoutedatcampuscops.Seldomwerethey"pig"or"fascist."Farmoreoften,
Soilqualityisoneofthemostbasicandperhapsleastunderstoodindicatorsoflandhealth.Soilsupportsplantgrowthandrep
最新回复
(
0
)