首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motocycle类。要求将vehicle作为虚基类
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motocycle类。要求将vehicle作为虚基类
admin
2015-06-27
64
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motocycle类。要求将vehicle作为虚基类,避免二义性问题。
请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
Avehicleisrunning!
Avehiclehasstopped!
Abicycleisrunning!
Abicyclehasstopped!
Amotorcarisnmning!
Amotocycleisrunning!
注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
classvehicle
{
private:
intMaxSpeed;
intWeight;
public:
vehicle():MaxSpeed(0),Weight(0){}
vehicle(intmax_speed,intweight)
:MaxSpeed(max_speed),Weight
(weight){}
//**********found**********
________Run()
{
cout<<"AvehicleiSrunning!"<
}
//**********found**********
________Stop()
{
cout<<"Avehiclehasstopped!"<
}
};
classbicycle:virtualpublicvehicle
{
private:
intHeight;
public:
bicycle():Height(0){}
bicycle(intmax_speed,intweight,intheight)
:vehicle(max_speed,weight),Height(height){};
voidRun(){cout<<"Abicycleisrunning!"<
voidStop(){cout<<”Abicyclehasstopped!”<
);
classmotorcar:virtualpublicvehicle
{
private:
intSeatNum;
public:
motorcar():SeatNum(0){}
motorcar(intmaxspeed,intweight,intseat_num)
//**********found**********
:________{}
voidRun(){cout<<"Amotorcaris
running!"<
voidStop(){cout<<"Amotorcar
hasstopped!"<
};
//**********found**********
classmOtOrcycle:________
{
public:
motorcycle(){}
motorcycle(intmax_speed,intweight,intheight,intseet_num):
bicycle(max_speed,weight,height),motorcar(max_speed,weight,seet_num){};
~motorcycle(){};
voidRun(){cout<<"Amotorcycleisrunning!"<
voidStop(){cout<<"AmotOrcyclehasstopped!"<
};
intmain()
{
vehicle*ptr;
vehiclea;
bicycleb;
motorcarc;
motorcycled;
a.Run();a.Stop();
b.Run();b.Stop();
ptr=&c;ptr->Run();
ptr=&d;ptr->Run(),
return0;
}
选项
答案
(1)virtual void (2)virtual void (3)vehicle(max_speed, weight), SeatNum(seat_num) (4)public bicycle, public motorcar
解析
(1)和(2)主要考查考生对虚函数的掌握,虚函数使用virtual定义。
(3)主要考查考生对构造函数的掌握,使用成员列表初始化。
(4)主要考查考生对派生类的掌握,派生类继承基类时要表明继承方式,公有继承为public,多个继承时要使用","隔开。
转载请注明原文地址:https://kaotiyun.com/show/l2BD777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
简述统计假设检验中两类错误的定义及其关系。
“要尽量多地要求一个人,也要尽可能地尊重一个人”体现了马卡连柯的
推动高中的多样化与特色化发展的要求不包括
某工业企业有房屋三幢,其中两幢房屋用于本企业生产经营,其账面原值为670万元,另一幢房屋出租给一商业企业,账面原值为120万元,年租金80万元。要求:计算该工业企业当年应纳的房产税税额(当地政府规定计税时允许按房产原值一次减除30%)。
结合实际,论述在我国坚持公民在适用法律上一律平等原则的现实意义及其要求。
随机试题
下列组织中对Χ线照射最敏感的是
某公司2007年12月31日有关财务资料如下:现金75000元,应收账款(净额)225000元,存货270000元,短期投资40000元,固定资产(净额)500000元,应付账款120000元,应付票据50000元,一年内到期的长期负债30000元。那么
()主要指产品水平、档次、技术含量和主要服务对象。应优先考虑同类主流产品和主流技术。
公司上市辅导工作开始前10个工作日内,辅导机构应当向证监会派出机构提交的材料有()
设立证券公司的主要股东需具有持续盈利能力,信誉良好,最近()年无重大违法违规记录,净资产不低于人民币()元。
商业银行为了更好的管理流动性风险,下列最不恰当的做法是()。
不安抗辩权是双务合同中的()享有的法定权利。
关于公文写作,一份完整的计划应包括的内容有()。
[*]
Islanguage,likefood,abasichumanneedwithoutwhichachildatacriticalperiodoflifecanbestarvedanddamaged?Judgin
最新回复
(
0
)