首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-02-22
16
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t="乐器",string n="无名"):type(t),name(n) { }
virtual string GetType() const { return "乐器"; }
virtual 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、乐器-无名
答案
A
解析
本题考查虚函数的运用,本题中基类Instrument,派生类Piano,其中虚函数为GetType,当定义Instrument *pi=new Piano("星空")时,调用派生类的GetType函数,得到type为钢琴,name为星空,所以输出钢琴-星空。选项A正确。
转载请注明原文地址:https://jikaoti.com/ti/M8h0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespacestd;intmain(){intf,f1=0,f2=1;for(inti=3;i
当派生类从一个基类保护继承时,基类中的一些成员在派生类中成为保护成员,这些成员在基类中原有的访问属性是()。
下列关于C++函数的说明中,正确的是()。
若MyClass为一个类,执行“MyClassa[4],*p[5];”语句时会自动调用该类构造函数的次数是()。
设有课程关系模式如下:R(C#,Cn,T,TA)(其中C#为课程号,Cn为课程名,T为教师名,Ta为教师地址)并且假定不同课程号可以有相同的课程名,每个课程号下只有一位任课教师,但每位教师可以有多门课程。该关系模式可进一步规范化为
请打开考生文件夹下的解决方案文件proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:Thereisawhite
下列关于thiS指针的叙述中,正确的是()。
某二叉树共有12个结点,其中叶子结点只有1个。则该二叉树的深度为(根结点在第1层)()。
设二叉树的后序序列为DGHEBIJFCA,中序序列为DBGEHACIFJ。则前序序列为
随机试题
人文主义的内涵。
下列诊断首先考虑的是若CT提示脑正中裂及右大脑外侧裂、枕大池高密度影,诊断为
根据《建设工程质量管理条例》,设备安装和装修工程的最低保修期限是()年。
根据《建设工程质量管理条例》,供热系统的最低保修期为()。
关于国内安全保卫,下列说法正确的是()
医务界流传着这样一个“四句话说死病人”的故事。一位农村患者好不容易借了钱,去认为“水平高”的县医院挂了一个专家号。专家见面看了看检查报告,连续说了三句话:“你来晚了”“没治了”“回家吧!”这时病人的精神快受不了了,急忙央求医生:“大夫,你给看看还有没有其他
汽博会开幕在即,甲、乙、丙三个人得到了两张参观票,于是三个人通过抽签决定这两张票的归属。在所设计的三个签中有两个签上写着“有”,一个签上写着“无”,抽签顺序是甲先、乙次、丙最后抽取。如果已知乙已经抽到了参观票,则甲也抽到参观票的概率是()。
用SQL的CREATE命令建立借阅表(字段顺序要相同),请对下面的SQL语句填空:______
Readtheextractbelowfromacompanyreport.Inmostofthelines(34-45),thereisoneextraword.Itiseithergrammatically
Fromthefirsttwoparagraphswemayinferthattheauthorthinksoneofthecomputer’slimitationsisthat______.Bysaying
最新回复
(
0
)