首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-06-10
30
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t="乐器",string n="无名"):type(t),name(n) { }
string GetType() const { return "乐器"; }
string GetName() const { return "无名"; }
protected:
string type,name;
};
class Piano:public Instrument{
public:
Piano(string n,string t="钢琴"):Instrument(t,n) { }
string GetType() const { return "钢琴"; }
string GetName() const { return name; }
};
int main(){
Instrument *pi=new Piano("星空");
cout<
GetType()<<’-’<
GetName();
delete pi;
return 0;
}
运行时的输出结果是
选项
A、乐器-星空
B、乐器-无名
C、钢琴-星空
D、钢琴-无名
答案
B
解析
本题考查派生类的应用,本题中基类Instrument,派生类Piano,当定义Instrument *pi=new Piano("星空")时,pi为指向基类的指针,那么执行pi->GetType()时调用基类的GetType函数,得到type为乐器,name为无名,所以输出乐器-无名。选项B正确。
转载请注明原文地址:https://www.kaotiyun.com/show/Wkfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespacestd;classTV{public:TV(ints=41):size(s){}
有如下类定义:classPet{charname[30];public:Pet(char*n){strcpy(name,n);}voidbark(){co
有三个关系R、S和T如下:则由关系R和S得到关系T的操作是
有如下类声明:classMau{intk;constintm;public:Mau(intk1,intm1);};则构造函数Mau的下列定义
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中定义的IntArray是一个用于表示整型一维数组的类。成员函数swap可以将数组中的两个指定元素交换位置;成员函数sort的功能是将数组元素按照升序排序。请编写成员函数sort
下面是重载为非成员函数的运算符函数原型,其中错误的是
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程包含有一个源程序文件proj2.cpp,其中定义了Stack类和ArrayStack类。Stack是一个用于表示数据结构“栈”的类,栈中的元素是字符型数据。Stack
有如下程序:#includeusingnamespacestd;classBase{intm;public:Base(){cout
有如下程序:#includeusingnamespacestd;classA{public:A(inti){x=i;}voiddispa(){cout
C++系统预定了4个用于标准数据流的对象,下列选项中不属于此类对象的是()。
随机试题
子宫来源于
哪种利尿药可用于治疗尿崩症
某施工单位承接了一段二级道路施工,其中包括3道结构形式和工程量基本相同的涵洞。根据工期要求,对于3道涵洞施工要求组织几个相同的工作队,在同一时间、不同的空间上进行施工。按照资源计划的要求,施工涵洞时安排的技术工人主要有测量工、机修工、钢筋工、木工、混凝
进行买入套期保值时,只要基差走弱,就一定会有净盈利;进行卖出套期保值时,只要基差走强,就一定会有净盈利。()
(2017·广东)人的身心发展具有不可重复性的特点,少年期学生的抽象思维能力还比较弱,对抽象的道理不易理解。()
59,40,48,(),37,18
Itissimpleenoughtosaythatsincebookshaveclasses—fiction,biography,poetry—weshouldseparatethemandtakefromea
竞争激烈
A、She’llgototheconcert.B、She’llhaveameeting.C、She’llwatchherneighbor’schildren.D、She’llvisitherneighbor.C信息明示题
A、Sheisn’thavingmuchtrouble.B、Sheunderstoodthereadingyesterday.C、Sheunderstandsverylittle.D、Sheisgoodatintensi
最新回复
(
0
)