首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motofcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motofcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2016-06-12
50
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motofcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//******fomld*****”。#include
class vehicle
{
private:
int MaxSpeed;
int Weight,
public:
//**********found**********
vehicle (int maxspeed, int
weight):________
一vehicle()f);
int getMaxSpeed() {return MaxSpeed;}
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){)
int getSeatNum(){return SeatNum;);
),
//**********found**********
class mOtOrcycle :_________
{
public:
motorcycle (int maxspeed, int weight,int height):vehicle(max’speed,weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,
weight,1){)
};
void main()
{
motorcycle a(80,150,1 00);
cout<
cout<
cout<
cout<
}
选项
答案
(1)MaxSpeed(maxspeed),Weight(weight){}; (2)virtual (3)virtual (4)p,ublic bicycle,public motorcar
解析
本题考查vehicle类及其派生类motorcar和bicycle,再由这两类派生出motorcycle类,其中涉及构造函数、成员函数和析构函数。构造函数采用成员初始化列表来完成对私有成员的初始化,派生类的书写要注意关键字。
【解题思路】
(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员MaxSpeed和Weight初始化。
(2)主要考查考生对派生类的掌握,题目要求将vehicle作为虚基类,避免二义性问题。因此在这里添加virtual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorcar和bicycle作为基类,再派生出motorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getSeatNam函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。
【解题宝典】
虚基类继承时要添加关键字virmM,以避免二义性。
转载请注明原文地址:https://kaotiyun.com/show/fYNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
设i,j,k均为int型变量,则执行完for(i=0,j=10;i<=j;i++,j--)k=i+j语句后,k的值为【】。
有以下程序:#include<iostream>usingnamespacestd;classsample{private:intx;public:voidsetx(i
t为int类型,进入下面的循环之前,t的值为0。while(t=1){...}则以下叙述中,正确的是()。
设有以下定义和程序:#include<iostream.h>classA1{public:voidshowl(){cout<<"classA1"<<end1;
为使该程序执行结果为10,那么应该在程序划线处填入的语句是()。#include<iostream>usingnamespacestd;classMyClass{public:MyClas
下列关于构造函数的描述中,错误的是()。
若调用一个函数,且此函数中没有return语句,则正确的说法是该函数
若有以下程序:#include<iostream>usingnamespacestd;classBase{private:inta,b;public:Base(intx
下列叙述中,正确的是()。
下列哪个是C++语言的有效标识符?
随机试题
下列不属于库存现金内部控制活动的是()
FrankLloydWrightprobablyisthegreatestarchitectthattheUnitedStateshaseverproduced.Hewasvery【21】andhadanatural
A.血管紧张素ⅠB.血管紧张素ⅡC.去甲肾上腺素D.醛固酮E.肾素
2007年甲公司委托乙公司加工商品一批(属于应税消费品)。有关经济业务如下:(1)1月5日,发出材料一批,计划成本为400000元,材料成本差异率为2%。(2)2月8日,支付商品加工费20000元,支付应当交纳的消费税43000元。该
()根据托运人的要求,将同一船舶的同一装货港、同一卸货港、同一收货人的两批或两批以上相同或不同的货物合并签发的一套提单。
社会总需求是指()。
下列场景最不可能发生的是()。
Amajorreasonforconflictintheanimalworldisterritory.Themaleanimal【1】anarea.Thesizeoftheareaissufficienttop
Ifyou’vegotanearforlanguages,askillofcodingorasteadyhandanddon’tfaintatthesightofbloodthenyourcareerlo
ScientistssaytherehasbeenaseveredecreaseintheamountofwaterinLakeChadinnorthernAfricainthelastthirtyyears.
最新回复
(
0
)