首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicyele作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicyele作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2017-07-04
42
问题
请使用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全国计算机二级
相关试题推荐
以下程序的输出结果是 main() {int a=4,b=5,c=0,d; d=! a&&! b||! c; cout<<d<<cndl; }
下列程序编译时发现pb->f(10);语句出现错误,其原因是【 】。#include<iostream.h>classBase{public:voidf(intx){cout<<"Base:"<<
在用class定义一个类时,数据成员和成员函数的默认权限是【】。
在关系数据库中,用来表示实体之间联系的是【 】。
属于关系的基本类型的是( )。
将7个数据进行插入排序,在最坏情况下需要比较的次数是
下列输出字符,A,的方法中,()是错误的。
下列字符串中,正确的C++标识符是()。
数据流图采用4种符号表示______、数据源点和终点、数据流向和数据加工。
随机试题
牛股膝关节前方具有()
一存活多年的同种异体肾移植接受者的体内虽有供体HLA人白细胞抗原表达,却未发生明显的排异反应。其原因可能是
对酒精中毒患者的护理措施,错误的是()。
某地区某类房地产2004年4月1日至10月1日的价格指数分别为79.6%、74.7%、76.7%、85.0%、89.2%、92.5%、98.1%(以2002年1月1日为100%)。其中有一房地产在2004年8月1日的价格为2000元/m2,对其作交易日
中国古代五行说,把五行跟五方、五色相匹配。下列各项匹配正确的是()。
行政机关应当在听证的()日前,通知当事人举行听证的时间、地点。
我国国家赔偿的责任主体是()。
《四月提纲》(南京大学1997年世界近现代史真题)
GolaxyisanotherartificialintelligenceGoprogramdevelopedbyGooglewhichwillcompeteagainstKeJieinApril.
Theywerecominghomefromapark,onthisweekend,afterplaying.Andforthis,a10-year-oldandhis6-year-oldsisterendedu
最新回复
(
0
)