首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2020-06-29
22
问题
有如下程序:
#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=newPiano("星空")时,pi为指向基类的指针,那么执行pi->GetType()时调用基类的GetType函数,得到type为乐器,name为无名,所以输出乐器-无名。选项B正确。
转载请注明原文地址:https://jikaoti.com/ti/Ael0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中使用友元函数访问类的私有数据成员,求出两个数据成员的大于1的最小公因子。请编写友员函数FriFun,使其输出结果为:rnmmondenominatoris2要求:补充编制的内
下列语句或语句序列中有语法错误的是
下列关于栈的叙述正确的是( )。
Windows环境下,由C++源程序文件编译而成的目标文件的扩展名是
下列运算符中,不能被重载的是
请使用VC6或使用【答题】菜单打开考生文件夹pmj2下的工程pmj2,其中有矩阵基类MatrixBase、矩阵类Matrix和单位阵UnitMatrix的定义,还有main函数的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结
下列关于基类和派生类关系的叙述中,正确的是
下列语句中错误的是
深度为7的二叉树共有127个结点,则下列说法中错误的是
算法的有穷性是指()。
随机试题
间接抗球蛋白试验检测何类抗体
(2006年)测量工作的基准线是()。
个人商用房贷款期限最长不超过()年。
国家助学贷款一般在()内还清。
把秋季集中产出的大米储存起来,起到稳定大米价格的功效,这是仓储的()。
公安机关对发现或者受理的案件暂时无法确定为刑事案件或者行政案件的,必须先按照刑事案件的程序办理。()
智力是创造力的充要条件。(2010年)
Facebookhasbeen【C1】______withfireandhasgotitsfingersburned,again.OnNovember29thAmerica’sFederalTradeCommission
WWW的超链接中定位信息所在位置使用的是______。
A、Tokeepfit.B、Tostudywell.C、Toearnmoremoney.D、Togainesteem.A事实细节题。短文开头提到,新年伊始是制订塑身计划的好时候,努力做一个身材匀称、健康快乐的人。
最新回复
(
0
)