首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-07-22
13
问题
有如下程序:
#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全国计算机二级
相关试题推荐
有如下程序: #qnclude<iostream> #include<iomanip> using namespace std; class CSum { int x,y;
下列关于栈的描述中错误的是
下面程序的输出结果为【】。#include<iostream>usingnamespacestd;voidinitialize(intprintNo,intstate=0);voidinitialize(
下面程序的运行结果为#include<iostream.h>classA{staticintn;public:A(){n=1;}A(intnum){n=
下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false。请在横线处填上适当内容,实现该函数。boolfun(char*str){inti=o,i=0;while(str[j])【】
在关系运算中,【】运算是对两个具有公共属性的关系所进行的运算。
下面程序的输出结果是【】。#include<iostream>usingnamespacestd;classbase{protected:inta;public:bas
已知:doubleA(doubleA){return++a;}和intA(intA){return++a;}是一个函数模板的两个实例,则该函数模板定义为【】
关于抽象类,下列表述正确的是()。
关于虚函数,下列表述正确的是()。
随机试题
求由方程表示的函数的一阶导数dy/dx和二阶导数d2y/dx2.
委托代理人为了被代理人的利益转委托他人代理时,下列情况中,复代理人代理行为的法律后果由被代理人直接承担的是()。
患者,男性,60岁。因“四肢不自主抖动伴运动不灵活7年”入院。该患者于7年前无明显诱因出现左上肢轻微震颤。2年后左下肢亦出现震颤,特别是在静止时明显,左侧肢体活动欠灵活,动作迟缓。入院前3年患者右侧上、下肢亦相继出现震颤,并逐渐加重,情绪紧张时加剧,入睡后
6岁女童,喜食泥块,面色萎黄,Hb92g/L,应给下列何种药物治疗
慢性肺心病急性加重期综合治疗措施包括
某外商甲与国内企业乙约定设立中外合作企业,下列关于甲乙合作方式的描述中,正确的有()。
第二次世界大战中,世界人民为了战胜法西斯建立了广泛的反法西斯同盟,该同盟形成的标志是()。
对比性分析:《唐律疏议·名例律》:“诸本条别有制,与例不同者,依本条。”《大明律附例·名例律》:“凡律自颁降日为始,若犯在已前者,并依新律拟断。”问题:这两段文字反映了什么问题?为什么会出现这种问题?
设an>0,bn>0,(n=1,2,…),且满足试证:(Ⅰ)若级数an收敛;(Ⅱ)若级数bn发散.
小向使用了一部标配为2GRAM的手机,因存储空间不够,他将一张64G的mircoSD卡插到了手机上。此时,这部手机上的2G和64G参数分别代表的指标是()。
最新回复
(
0
)