首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2017-02-21
59
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include<iostream.h>
class vehicle
{
private:
int MaxSpeed;
int Weight;
public:
//**********found**********
vehicle(int maxspeed,int
weight):_______
~vehicle(){};
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
(maxspeed, weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,1){}
};
VOid main()
{
motorcycle a(8 0,150,100);
cout<<a.getMaxSpeed() <<end1;
cout<<a.getWeight()<<end1;
cout<<a.getHeight()<<end1;
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调用getHeight函数和getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。
转载请注明原文地址:https://kaotiyun.com/show/z6Ap777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
以下程序的输出结果是【】。#include<iostream.h>unsignedfun(unsignednum){unsignedk=1;do{k*=num%10;n
所有在函数中定义的变量,连同形式参数,都属于
以下程序的输出结果是#include<iostream.h>voidmain(){inti,j,x=0;for(i=0;i<2;i++){x++;
设置虚基类的目的是()。
当使用fstream流类定义一个流对象并打开一个磁盘文件时,文件的隐含打开方式为()。
以下程序中函数scmp的功能是返回形参指针s1和s2所指字符串中较小字符串的首地址。#include<string>char*scmp(char*s1,char*s2){if(strc
以下定义数组中错误的是
以下各选项组中,均是C++语言关键字的组是
数据结构分为逻辑结构和存储结构,循环队列属于______结构。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
随机试题
提出“精神胚胎”“有吸引力的心理”的教育家是()
章太炎反对代议政体的法律思想集中体现于
激励因素
在Excel2010中公式或函数对单元格的引用类型包括__________。
城市规划信息化最为基础性的工作是()
下列各项中,应计入增值税的应税销售额的有()。
以下选项中,符合所给图形的变化规律的是()。
“六一”期间,中央商场搞“家电下乡”活动,农民购买家电时可享受政府补贴13%的优惠政策。张大伯家买了一台电冰箱,只需付1392元,这台冰箱的原价是___________元。
把栏杆拍遍 梁衡中国历史上由行伍出身,以武起事,而最终以文为业,成为大诗词作家的只有一人,这就是辛弃疾。这也注定了他的词及他这个人在文人中的唯一性和在历史上的独特地位。辛弃疾
JourneyinCatastrophes:ThreeFormsofViolentStormsI.WindsandstormsA.Winds’movinginviolentstorms—bringingabout
最新回复
(
0
)