首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中
admin
2020-10-21
19
问题
请打开考生文件夹下的解决方案文件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() ( returnMaxSpeed;}
int getWeight() {returnWeight;}
};
//**********found**********
class bicycle:__________public
vehicle
{
private:
int Height;
public:
bicycle(int maxspeed,int weight,int height):vehicle(maxspeed, weight),Height(height){}
int getHeight(){returnHeight ;};
};
//**********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;);
};
//**********Ic found**********
class motorcycle :___________
{
public:
motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed, weight),bicycle(maxspeed,weight,height),motorcar(maxspeed,weight,1){}
};
void msin()
{
motorcycle a(80,150,100);
cout<<a.getMaxSpeed()<<endl;
cout<<a.getWeight()<<endl;
cout<<a.getHeight()<<endl;
cout<<a.getSeatNum()<<endl;
}
选项
答案
(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://jikaoti.com/ti/JEl0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:(1)类CBase有一个常数变量Number1,在构造函数时对其初始化,请在注释//********1********后
下面程序的输出结果是()。#include<iostream.h>#include"string.h"voidmain(){chara[]="HelloTest",b[]="Test";strcpy(a,b);cout<<a<<e
使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:number1=anumber2=anumber1=anumber2=b注意:错误的语句在//******error******
阅读下面程序:#include<iostream.h>fun(inta,intb){intc;c=a+b:returnC;)voidmain(){intx=6,y=7,z=8,r;r=fun((x--,y++,x+y),z-
以下程序的执行结果是()。#include<iostream.h>classTestClass2{public:TestClass2(){};TestClass2(inti,intj);voidprintb();privat
下列各选项中,不属于序言性注释的是()。
定义派生类时,若不使用关键字显式地规定采用何种继承方式,则默认方式为()。
关于函数重载,下列叙述中错误的是()。
下列叙述中正确的是()。
在数据库系统的组织结构中,下列()映射把用户数据库与概念数据库联系了起来。
随机试题
背景装饰公司承接了综合楼食堂装饰工程,食堂隔墙为砌筑结构,砌筑时按要求在2.1m(门洞上口)增加了一道圈梁,顶部和梁或板交接处采用红砖斜砌,防火门框安装时先用射钉固定,再用砂浆封堵。装饰内容有墙面干挂烧毛石材、矿棉板吊顶、金属吊顶、厨房墙地砖。食堂层高5
产卵量最大的线虫是
防风通圣丸的功效有
下列治疗军团菌病的首选药是
大江三郎诉市东区公安分局处行政拘留案日本人大江三郎为日本W公司派驻在我国常年工作的员工,其在我国某市工作期间,因一次嫖娼行为被某市东区公安分局处行政拘留15日,并处罚款5000元。大江三郎完成W公司派驻工作回国后委托日本律师向某市中级人民法院起诉,中级人
【背景资料】某城市道路改造工程,随路施工的综合管线有0.4MPa的DN500mm中压燃气、DN1000mm给水管并排铺设在道路下,燃气管道与给水管材均为钢管,实施双管舍槽施工。热力隧道工程采用暗挖工艺施工。承包方A公司将工程的其中一段热力隧道工程
清代素菜的派别包括()。
当地时间2014年6月2日,中国常驻联合国副代表王民向联合国秘书长交存了中国政府接受《(京都议定书)多哈修正案》的接受书,这表明中国高度重视应对()变化工作,将其作为建设生态文明和美丽中国的重要组成部分,列入国家发展规划。
设计软件结构是在软件生命周期的()。
Theseniorcitizenexpressedasentimentwhich______profoundlytoeveryChineseheart.
最新回复
(
0
)