首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> #include<string> using namespace std; class Instrument{ public: InStrument(s
有如下程序: #include<iostream> #include<string> using namespace std; class Instrument{ public: InStrument(s
admin
2020-06-29
27
问题
有如下程序:
#include<iostream>
#include<string>
using namespace std;
class Instrument{
public:
InStrument(string t=”乐器”,string n=”无名”):type(t),Dame(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{retum name;}
};
int main(){
Imtnnnent*pi=new Piano(”星空”);
cout<<pi一>GetType()<<’一’<<pi一>GetName();
delete pi;
return 0;
}
运行时的输出结果是( )。
选项
A、钢琴一星空
B、钢琴一无名
C、乐器一星空
D、乐器一无名
答案
A
解析
本题考查虚函数的运用,本题中基类Instrument,派生类Piano,其中虚函数为GetFype,当定义Instrument*pi=new Piano(”星空”)时,调用派生类的GetType函数,得到type为钢琴,name为星空,所以输出钢琴一星空。选项A正确。
转载请注明原文地址:https://kaotiyun.com/show/pi8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
执行下列语句,变量sum的值是______。intsum=0;for(inti=1;i<=3;i++)for(intj=1;j<=i;j++)sum++;
如下程序的输出结果是______。#include<iostream>usingnamespacestd;classpumpkin{public:pumpkin(){++count;}~p
类定义如下:classTestClass{public:TestClass(){cout
如果在表达式++x/y中,++是作为友元函数重载的,/是作为成员函数重载的,则该表达式还可为
有如下函数模板的定义:template<classT>Tfunc(Tx,Ty){returnx*x+y*y;}在下列对func()的调用中,不正确的是()。
对于结构中定义的成员,其隐含访问权限为______。
在长度为n的有序线性表中进行二分查找,需要的比较次数为【】。
下面关于C++语言的描述错误的是
派生类的成员函数不能访问基类的()。
使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:(1)完成构造函数,设置数组元素的个数为0,请在注释//********1********之后添加语句。
随机试题
BrightonisapopularseasidetownonthesouthcoastofEngland.Notlongago,somepolicemenwerevery【21】.There【22】severals
脊髓损伤患者急性期康复治疗是指实施的时间在伤后
睾丸炎的治疗措施不包括
民法法系的发展是以()。
工商业活动集聚的场所是(),也是从事工商业活动的人群聚居的场所。
某商品经过两次降价,由每件100元降至81元,则平均每次降价的百分率为()。
2006年哪个地区的电信固定资产投资额最低()。与2005年相比,2006年中部地区的电信业务收入占全国的比重约()。
Thestorytookplaceinasmalltown______themorningofFebruary6.
Jupiter______perhapsthemostimportantplanetofthesolarsystem.
Childpsychologists—andkindergartenteachers—havelongknownthatwhenchildrenfirstshowupforschool,someofthemspeaka
最新回复
(
0
)