首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。清在程序中
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。清在程序中
admin
2019-04-24
77
问题
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出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 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(80,150,1 00);
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类。在主函数中可以看到motoreycle类的实例a调用getHeight函数和getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bieycle,public motorcar。
转载请注明原文地址:https://kaotiyun.com/show/3OAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
非成员函数应声明为类的______函数才能访问这个类的private成员。
已知一个函数的原型是:intfn(doublea);若要以5.27为实参调用该函数,应使用表达式______。
以下函数实现的功能是______。voidfun(char*s){char*p,*q,temp;p=s;q=s+strlen(s)-1;while(p<q){temp=*p;*p=*
执行以下程序后,输出“*”号的个数是______。#include<iostream.h>main(){inti,j;for(i=1;i<5;i++)for(j=2;j<=i;j++)cout<<’
有如下程序:#include<iostream>usingnamespacestd;classTestClass1{public:virtualvoidfun(){cout<<"1";}};
按照标识符的要求,下列选项中,()符号不能组成标识符。
以下哪个不是C++语言中的有效标识符?
A、 B、 C、 D、 Dc++语言中析构函数为符号“~”加类名,且析构函数没有返回值和参数,故前不加void关键字。所以正确的形式应该是~Myclass()。
随机试题
A.第1对鳃弓B.额鼻突C.二者均参与D.二者均不参与颈的形成()
A色谱定性分析B色谱系统柱效的计算C色谱定量分析D色谱分离度计算E色谱峰对称性的考察相邻两峰的保留时间及两峰的峰宽用于
可导致尿酸增高的是()
根据《中华人民共和国药典临床用药须知》中规定,在注射前必须做皮试的药物是()。
在下列各项中,不属于责任成本基本特征的是( )。
国务院的领导体制是()。
设α是n维列向量,已知αTα阶矩阵A=E-ααT,其中E为n阶单位矩阵,证明矩阵A不可逆.
根据“tCourse”表的结构,判断并设置主键。
存储400个24×24点阵汉字字形所需的存储容量是
AControlofRespirationBBeautyofFreshCutFlowersCRoleofRespirationDMostImportantAspectofFlowerCareENeed
最新回复
(
0
)