首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2020-05-14
66
问题
请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
class vehicle
{
private:
int MaxSpeed;
int Weight;
pubhc:
//**********found**********
vehicle(int maxspeed,int weight):________
~vehicle(){};
int getMaxSpeed(){return MaxSpeed;}
int getWeight(){retum 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:
motorear(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,100);
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作为基类,再派生出Inotorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getSeatNum函数,由此可知这两个基类都是公有继承,因此得出语句:public bicyck,public motorcaro
转载请注明原文地址:https://www.kaotiyun.com/show/nM8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的输出结果是非曲直【 】。#include<iostream,h>classbase{intx,y;public:base(inti,intj){x=i;y=j;}virtualintadd(){
若,将一个二元运算符重载为类的成员函数,其形参个数应该是______个。
下列关于虚函数与函数重载区别的叙述中不正确的是
有如下程序:#include<iostream>usingnamespacestd;classBase{public:virtualvoidfunc1(){cout<<"Base1";}
定义如下枚举类型:enum{Monday,Tuesday,Wednesday,Thrusday,Friday=2};,则下列语句正确的是
按照标识符的要求,下列选项中,()符号不能组成标识符。
下面是一个模板声明的开始部分: Template<typename T>double... 由此可知
下面是复数类complex的定义,其中重载的运算符“+”的功能是返回一个新的复数对象,其实部等于两个操作对象实部之和,虚部等于两个操作对象虚部之和;请补充完整。classcomplex{doublereal;
下面关于虚函数的表述中正确的是()。
随机试题
学生应该正视学习中的困难,而不要逃避它们。
以下哪项不属于排痰训练
等渗性缺水患者大量输入生理盐水治疗可导致
为加强麻醉药品和精神药品经营管理,保证合法、安全流通,防止流入非法渠道,根据《麻醉药品和精神药品管理条例》,原国家食品药品监督管理局制定了《麻醉药品和精神药品经营管理办法(试行)》,并于2005年10月31日发布,自发布之日起施行。经哪个部门批准,实行
继电保护设计时应满足的要求是()。
下列项目中,不属于原始凭证的是()。
按照实施审计的范围,可以将审计划分为()。
甲公司为增值税一般纳税人,适用的增值税税率为13%,2019年10月初“应交增值税”借方余额为6万元,当月发生如下业务: (1)建造办公楼领用本单位产品,成本为15万元(其中直接材料10万元),计税价格18万元。 (2)外购原材料一批,价款30万元(不
Adolescentsaretakinglongertobecomefullyproductivemembersofsociety,ReedLarson,professorofhumandevelopment,Univer
A、Theyvisitrelativesandfriendsandcleanthehouse.B、TheyvisitashrinetoprayforhealthandgoodfutureC、Theirfamily
最新回复
(
0
)