首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。清在程序中
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。清在程序中
admin
2019-04-24
35
问题
请打开考生文件夹下的解决方案文件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全国计算机二级
相关试题推荐
下列关于派生类构造函数和析构函数的说法中,错误的是()。
设有以下定义和程序:#include<iostream.h>classA1{public:voidshow1(){cout<<"classA1"<<end1;}};cla
下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false,则横线处应填上()。Boolfun(char*str){inti=0,j=0;while(str[j])j++;for(j
栈C最多能容纳4个元素,现有6个元素按A、B、C、D、E、F的顺序进栈,下列哪个序列不是可能的出栈序列()。
已知一个函数的原型是:intfn(doublea);若要以5.27为实参调用该函数,应使用表达式______。
以下函数实现的功能是______。voidfun(char*s){char*p,*q,temp;p=s;q=s+strlen(s)-1;while(p<q){temp=*p;*p=*
有如下类声明:classTestClass1{intk;public:voidset(intn){k=n;}intget()const{returnk;}};classT
不改变关系表中的属性个数但能减少元组个数的是______。
下面关于虚函数的描述中正确的是()
下列字符串中,正确的C++标识符是()。
随机试题
关于我国的地理环境,下列说法不正确的是()。
属于消化腺的是【】
某企业占用林地100万平方米建造高尔夫球场,还占用林地50万平方米开发经济林木,所占耕地适用的定额税率为20元/平方米。该企业应缴纳耕地占用税()。
在对内部控制进行初步评价并进行风险评估时,下列各项中,注册会计师不需要在审计工作底稿中形成结论的是()。
________是进行全面发展教育,实现培养目标的基本途径。
A、 B、 C、 D、 B每组前两个图形叠加去同存异得到第三个图形。
根据下表,回答86-90题。世界部分城市气候状况注:第6、7、9、10、11、12列中温度、降水和日照指标之后的数字表示特定的月份。表中最冷月与最暖月温差在20度以上的城市有多少个?
根据我国《宪法》的规定,全国人大常委会根据最高人民法院院长的提请,可以任免的人员有()。
下列属于国务院职权的是()。
A、CheneyandKerryB、BushandKerryC、CheneyandtheheadofDemocraticPartyD、TheheadsofDemocraticandRepublicpartiesC
最新回复
(
0
)