首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-07-22
39
问题
有如下程序:
#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全国计算机二级
相关试题推荐
用树形结构表示实体之间联系的模型是
下列关于栈的描述中错误的是
在C++语言的结构化程序设计中,【】是程序的基本组成单元;在C++语言的面向对象设计框架中,【】是程序的基本组成单元。
下列程序的输出结果是【】#include<iOStream>usingnamespacestd;template<typenameT>Ttotal(T*datA){Ts=0;
下面程序的运行结果为#include<iostream.h>classA{staticintn;public:A(){n=1;}A(intnum){n=
下列叙述中正确的是
在面向对象方法中,允许作用于某个对象上的操作称为【】。
有以下程序:classDate{public:Date(inty,intm,intd);year=y;month=m;
下面程序的输出结果是【】。#include<iostream>usingnamespacestd;classbase{protected:inta;public:bas
随机试题
当企业签发空头支票,遭到银行退票,企业应当支付票面金额()赔偿金。
中国甲公司拟与外国乙公司共同投资设立丙中外合资经营企业。丙企业的注册资本为600万美元,其中甲公司出资400万美元,乙公司出资200万美元。合营合同约定中外投资各方分两期缴付出资。2011年5月10日,丙企业取得工商行政管理部门于2012年5月5日签发的营
气体能够充满密闭容器,说明气体分子除相互碰撞的短暂时间外,()。
设f(x)在[1,+∞)内可导,f′(x)<0且f(k)-∫1nf(x)dx.证明:{an}收敛且0≤an≤f(1).
A,B为n阶矩阵且r(A)+r(B)<n.证明:方程组AX=0与BX=0有公共的非零解。
It’snotjustlonelyatthetop;itcanbe"disengaging"too.Manyofthemostunhappy,unproductiveandpotentially【C1】______em
【26】【36】
PASSAGETHREEWhatistheconclusionofthewholepassage?
A、Teacher.B、Doctor.C、Worker.D、Student.D①选项都是对身份或职业的描述,因此预测问题可能与男士的身份职业相关。②女士问男士现在是不是在工作,男士说他是悉尼大学的学生,所以选D项student。
Bob:Whatareyoureading,Frank?Tom:It’sthisweek’sNewScientist,why?Bob:Iwasjustwondering--______,butI’veneverac
最新回复
(
0
)