首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2021-02-22
29
问题
有如下程序:
#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/K2fp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列控制对齐方式的操作符中,错误的是()。
有如下程序:#includeusingnamespacestd;classCD{public:~CD(){cout
每个学校有一名校长,且不同学校的校长可以是同一人,则实体学校和实体校长间的联系是
请打开考生文件夹下的解决方案文件proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:Thereisawhite
下列方法中,不属于软件调试方法的是()。
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,实现函数sort(intA[],int,n),用选择排序法把数组从大到小排序。提示:选择排序法的思想是:(1)反复从还未排好的那部分线性表中选择出关键字最小的
使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(char*s,char*s1,char*s2)中形参字符串s1和s2有相同的字符个数,且s1中各字符互不相同。该函数实现将已知字符串S中所有在字
下列有关类继承的叙述中,错误的是()。
一间宿舍可住多个学生,则实体宿舍和学生之间的联系是()。
有如下函数定义:voidswap(inta,int&b){intc=a;a=b;b=c;}若执行语句序列intx=0,y=1;swap(x,y);则变量x和y的值分别是
随机试题
产品市场定位策略有()
瞟呤核苷酸的分解代谢如何进行?
煤气站的生产、输送系统均应按规定设置放散管,且放散管至少应高出厂房顶()m以上并具备防雨和可靠的防倾倒措施。
FIDIC《施工合同条件》中,为了解决工程师的决定可能处理得不公正的情况,通用条件增加了( )处理合同争议的程序。
a至c1之间共包含几个半音?()
A、Theeffectofart.B、Thevalueoflearning.C、Theimportanceofcuriosity.D、Thepoweroffamilyeducation.A短文通篇介绍自己在艺术品博物馆的情
Forthispart,youareallowed30minutestowriteanessayrelatedtotheshortpassagegivenbelow.Inyouressay,youareto
Theconference____________(整整持续一周)bythetimeitends.
ThetravelerlookslikeanEnglishman,buthisf6reignaccentgavehim______.
Manystudentsfindtheexperienceofattendinguniversitylecturestobeaconfusingandfrustratingexperience.Thelecturersp
最新回复
(
0
)