首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-09-05
38
问题
有如下程序:
#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://kaotiyun.com/show/idfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespacestd;classBase{intm;public:Base(){cout
下列关于重载运算符错误的是
下列各组类型声明符中,含义相同的一组是()。
下列关于构造函数的描述中,错误的是()。
在软件开发中,需求分析阶段产生的主要文档是( )。
下面程序输出的结果为()。#inchdevoidfun(rota,intb){inttemp;temp=a;a=b:b=temp;}voidmain()
下面对软件特点描述错误的是
要建立文件流并打开当前目录下的文件file.dat用于输入,下列语句中错误的是()。
数据库设计中反映用户对数据要求的模式是()。
软件生命周期是指()。
随机试题
在Windows中,用鼠标左键将一个文件夹拖动到同一个磁盘的另一个文件夹时,系统执行是_______。
(77)Whatdowemeanbyasatisfactorystandardofliving?Obviously,itmustincludethebasicnecessitiesoflifesuchasfood
杏苏散中含有
苏子降气汤组成中不包含的药物是
在我国实施人类辅助生殖技术,下列各项中违背卫生部制定的伦理原则的是
一般而言。财富积累达到最高峰的时候是()。
青铜艺术大致可以分为几个时期?各时期有何艺术特色以及重要的代表作?
按照()的原则和“革命化、年轻化、知识化、专业化”的方针,加强领导班子建设,把各级领导班子建设成为政治坚定、开拓创新、团结协作、廉政勤政的领导班子。
TheChinaboomisbynowawell-documentedphenomenon.Whohasn’t【1】theMiddleKingdom’sastoundingeconomicgrowth(8percenta
在窗体上画两个名称分别为Text1、Text2的文本框和一个名称为Command1的命令按钮,然后编写如下事件过程:PrivateSubCommand1Click()DimxAsInteger,nAsIn
最新回复
(
0
)