首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument(string t=“乐器”,string n=“无名”):type(t),le(n){}
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument(string t=“乐器”,string n=“无名”):type(t),le(n){}
admin
2016-07-13
16
问题
有如下程序:
#include
#include
using namespace std;
class Instrument{
public:
Instrument(string t=“乐器”,string n=“无名”):type(t),le(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~tName()const{return nanle;}
};
int main(){
Itment*pi=new Piano(“星空”);
cout<
GetType()<<‘一’<
~tName();
delete pi;
return 0;
}
运行时的输出结果是( )。
选项
A、钢琴一星空
B、钢琴一无名
C、乐器一星空
D、乐器一无名
答案
A
解析
本题考查虚函数的运用,本题中基类Instrument,派生类Piano,其中虚函数为GetType,当定义Instrument*pi=new Piano(”星空”)时,调用派生类的GetType函数,得到type为钢琴,name为星空,所以输出钢琴一星空。选项A正确。
转载请注明原文地址:https://jikaoti.com/ti/DjE0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序#inclube<iostream.h>classClassOne{public:ClassOne(intv=O){i=v;cout<<i;}voidprint(){co
下列关于构造函数的描述中,错误的是()。
设有以下定义和程序:#include<iostream.h>classA1{public:voidshowl(){cout<<"classA1"<<end1;
下列关于函数模板实参不能省略的情况说明不正确的是
请定义一个函数名为A,返回值为int,没有参数的纯虚函数的定义是【】。
下列叙述中,正确的是()。
下面叙述正确的是______.
下面叙述错误的是()。
下列运算符中哪些是不能够被重载的?
随机试题
存储过程是使用SQL语句和流程控制语句编写的模块,存储过程经编译和优化后存储在中。
Adamsnowmaintainsthatitislessimportanttosavethenation______toaperilousfuture.
患者,男,1d前大量饮酒后出现腹痛,恶心,呕吐,查体:左上腹有横行呈带状压痛及肌紧张,左腰部皮下淤血而呈蓝色,该患者的诊断是
用B超检查健康动物的脾脏,探查位置应在
某患者具有胃痛病史30年,近日因饮骺出现胃脘隐痛,口渴不欲饮,大钎结难解,舌质红,苔少,脉细。治疗最佳方剂是
定期报告披露前出现业绩泄露。或者出现业绩传闻且公司证券及其衍生品种交易出现异常波动的,上市公司应当及时披露本报告期相关财务数据。()
参观游览开始,旅游团队在由饭店前往景点途中,地陪首先应介绍的内容是()。
两个调所有的音级都是等音关系,而且具有同样的调式意义,这样的两个调称为_________。
窗体中有文本框Text1、Text2和Text3。运行时在Text1中输入整数m,在Text2中输入整数n(m<n),单击按钮Command1,计算m到n之间(含m和n)全部奇数之和,然后在Text3中输出结果。事件代码如下:PrivateSubCo
A、Peopleworkinginalargefactory.B、Peoplewalkingoncrowdedcitystreets.C、Aneverydayactivityinasmalltown.D、Awell-
最新回复
(
0
)