首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。清在程序中
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。清在程序中
admin
2019-04-24
55
问题
请打开考生文件夹下的解决方案文件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
下列程序的输出结果是()。#include<iostream>usingnamespacestd;voidfun(int&r){r*=2;}intmain(){int
下列函数的功能是判断字符串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的顺序进栈,下列哪个序列不是可能的出栈序列()。
下列叙述中正确的是()。
以下函数实现的功能是______。voidfun(char*s){char*p,*q,temp;p=s;q=s+strlen(s)-1;while(p<q){temp=*p;*p=*
不改变关系表中的属性个数但能减少元组个数的是______。
下列字符串中,正确的C++标识符是()。
随机试题
行政许可法为了解决两个以上部门分别实施行政许可的事项时所面临的程序复杂和时限过长的问题,规定了三种可供选择的方式,下列哪一项不是()。
推销活动分析的程序:
患儿,男孩,7岁,因发热、意识障碍诊断为病毒性脑炎收入院治疗。该病80%有以下病毒引起
调节红细胞生成的主要体液因素是
卵圆孔在解剖上闭合的时间大多在()
幼儿园中班的规模为:
①这个简单的问题,经常使得工人们无所适从②现实所逼,建筑工人在维权遭遇困难时往往只能使用非正规的方式,以引起足够的关注③建筑工人比其他行业的农民工更多地面临欠薪、工伤得不到合理赔偿等问题④一项调查显示,2012年底仍有高达89.1%的建筑工人没有规范
无穷级数的收敛区间为________。
猫が車ひかれて、死んでいた。
Youhavereadanarticleinanewspaperwhichstatesthat"Childrenshouldbepaidfordoinghousework,forthishelpsthemtol
最新回复
(
0
)