首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motofcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motofcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基
admin
2016-06-12
48
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中定义了vehicle类,并派生出motofcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。请在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//******fomld*****”。#include
class vehicle
{
private:
int MaxSpeed;
int Weight,
public:
//**********found**********
vehicle (int maxspeed, int
weight):________
一vehicle()f);
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(max’speed,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)p,ublic bicycle,public motorcar
解析
本题考查vehicle类及其派生类motorcar和bicycle,再由这两类派生出motorcycle类,其中涉及构造函数、成员函数和析构函数。构造函数采用成员初始化列表来完成对私有成员的初始化,派生类的书写要注意关键字。
【解题思路】
(1)主要考查考生对构造函数的掌握,构造函数使用初始化列表来对私有成员MaxSpeed和Weight初始化。
(2)主要考查考生对派生类的掌握,题目要求将vehicle作为虚基类,避免二义性问题。因此在这里添加virtual使vehicle成为虚基类。
(3)主要考查考生对派生类的掌握,题目要求以motorcar和bicycle作为基类,再派生出motorcycle类。在主函数中可以看到motorcycle类的实例a调用getHeight函数和getSeatNam函数,由此可知这两个基类都是公有继承,因此得出语句:public bicycle,public motorcar。
【解题宝典】
虚基类继承时要添加关键字virmM,以避免二义性。
转载请注明原文地址:https://kaotiyun.com/show/fYNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若要定义一个只允许本源文件中所有函数使用的全局变量,则该变量需“要使用的存储类别是()。
关于C++语言与C语言关系描述中错误的是
C++语言中用于定义类的关键字是
有以下程序#inclube<iostream.h>classClassOne{public:ClassOne(intv=O){i=v;cout<<i;}voidprint(){co
有以下程序:#include<iostream>usingnamespacestd;intmain(){intintone;int&rInt=intone;intone=
下列描述中,表达错误的是()。
下列关于构造函数的描述中,错误的是()。
设有以下变量定义,并已赋确定的值:charw;intx;floaty;doublez;则表达式:w*x+z-y所求得的数据类型为()。
请定义一个函数名为A,返回值为int,没有参数的纯虚函数的定义是【】。
下列叙述中,正确的是()。
随机试题
在中医诊断学望舌中,可导致裂纹舌的有()。
A.复方铝酸铋片B.二甲双胍片C.甲氧氯普胺片D.瑞舒伐他汀片E.维生素C睡前服用,可使抑制肝脏合成胆固醇效果更好的药品是()。
在货物运输保险承包的风险中,一般外来风险包括()
玻璃板隔墙应()。
设定工程项目绩效目标指标的要求是()。
()是指由债务人或交易对手未能履行合同所规定的义务从而给银行带来损失的可能性。(2011年)
政府间事权及支出的划分一般应遵循的原则有()。
HeoftenattendspubliclecturesattheuniversityofCaliforniachiefly______hisEnglish.
民用航空器致人损害的免责事由为()
AGoalsBHistoryofWomen’sRightsMovementCStartofWomen’sRightsMovementDTraditionalStatusofWomenERights
最新回复
(
0
)