首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
有如下程序: #include #include using namespace std; class Instrument{ public: Instrument
admin
2015-07-22
42
问题
有如下程序:
#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全国计算机二级
相关试题推荐
若有以下程序:#include<iostream>usingnamespacestd;classBase{public:voidwho(){cout<<"Base"<<end1;}}
下列程序的输出结果是【】#include<iostream>usingnamespacestd;int&getVar(int*pint){return*pint;}intmain(
为了使类中的某个成员不能被类的对象通过成员操作符访问,则不能把该成员的访问权限定义为
下列函数的功能是判断字符串str是否对称,对称则返回true,否则返回false。请在横线处填上适当内容,实现该函数。boolfun(char*str){inti=o,i=0;while(str[j])【】
有如下程序: #include<iostream> using namespace std; class A { public: A(){cout<<"A";} }; class B<public:
有如下类声明: class MyBASE{ int k; public: void set(iht n){k=n;} int get()coast{return k;} }; class M
下面是复数类complex的定义,其中作为友元函数重载的运算符“--”的功能是将参数对象的实部减1,然后返回对该对象的引用。请补充完整。classcomplex{private:intreal;int
随机试题
分泌突然增加而诱发排卵的激素是
关于x线影像放大的叙述,错误的是
典型急性菌痢患者的粪便呈
A、上市药品B、现代药C、传统药D、国家基本药物E、基本医疗保险用药符合上条原则,市场能够保证供应,并经社保部门批准的药品是
厚朴的性状特征有
设总体X的概率密度为,其中θ>-1是未知参数X1,X2,…,Xn是来自总体X的样本,则θ的矩估计量是()。
通常亮度下,人眼睛瞳孔的直径约为3mm,视觉感受到最灵敏的光波波长为550nm(1nm=1×10-9m),则人眼睛的最小分辨角约为:
下列选项中,属于工程准备阶段文件的有()。
会计报表的编制必须符合以下要求:数字真实、内容完整、计算准确、说明清楚、编报及时、手续齐备等。( )
论述孔子的道德理论及其现代价值。(2012/2015年东北师大)
最新回复
(
0
)