首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-07-22
27
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t="乐器",string n="无名"):type(t),name(n) { }
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,其中虚函数为GetName,当定义Instrument *pi=new Piano("星空")时,调用派生类的GetType函数,得到type为乐器,name为星空,所以输出乐器-星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/AjNp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序: #include<iostream> using namespace std; class Base { protected: in i; public
下面程序的运行结果为#include<iostream.h>classA{staticintn;public:A(){n=1;}A(intnum){n=
数据结构分为逻辑结构和存储结构,循环队列属于工【 】结构。
下列关于类和对象的叙述中,错误的是
下列叙述中正确的是
在关系运算中,【】运算是对两个具有公共属性的关系所进行的运算。
函数swap(arr,n)可完成对arr数组从第1个元素到第n个元素两两交换。在运行调用函数中的语句后,a[0]和a[1]的值分别为上【】。a[0]=1;a[1]=2;swap(a,2);
语句ofstreamf("SALARY.DAT",ios::applios::binary);的功能是建立流对象f,试图打开文件SALARY.DAT并与之连接,并且
关于纯虚函数,下列表述正确的是()。
随机试题
清洗气路连接金属管内壁时应先用无水乙醇进行疏通处理。()
Tobeagoodteacher,youneedsomeofthegiftsofagoodactor:youmustbeableto【C1】______theattentionandinterestofyou
支链氨基酸代谢病的代表性疾病为
若合同当中的数量条款规定了卖方交货的数量可有5%的增减幅度,则合同中的价格条款也应作出相应的规定。()
乙公司2016年9月30日在证券市场上发行短期公司债券用于某项投资业务,债券按面值2000万元公开发行,乙公司承诺在6个月后以2100万元回购,乙公司发行债券的相关费用20万元,实际收到发行收入1980万元,乙公司将其确认为交易性金融负债。2016年12月
下列关于讯问犯罪嫌疑人的叙述正确的是()。
下列程序的功能是把顺序文件smtextl.txt的内容全部读入内存,并在文本框Textl中显示出来。请填空。PrivateSubCommand1_Click()DiminDataAsStringText1.Text=""Open"smt
「あの、これ、()物ですが……」「どうもありがとうございます。」
Sheisvery______upsettingherhusband,ashehasaviolenttemper.
MemoTo:KatherineAnderson,GeneralManagerFrom:StephenBlack,SalesDepartmentDate:19November,2013Subject:Resignation(
最新回复
(
0
)