首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2021-02-22
52
问题
有如下程序:
#include
#include
using namespace std;
class Animal{
public:
virtual string GetType() const { return "Animal"; }
virtual string GetVoice() const { return "Voice"; }
};
class Dog:public Animal{
public:
string GetType() const { return "Dog"; }
string GetVoice() const { return "Woof"; }
};
class Cat:public Animal{
public:
string GetType() const { return "Cat"; }
string GetVoice() const { return "Miaow"; }
};
void Type(Animal& a) { cout<
void Speak(Animal& a) { cout<
int main() {
Dog d; Type(d); cout<<" speak "; Speak(d); cout<<" - ";
Cat c; Type(c); cout<<" speak "; Speak(c); cout<
return 0;
}
运行时的输出结果是
选项
A、DogspeakVoice-CatspeakVoice
B、DogspeakWoof-CatspeakMiaow
C、AnimalspeakVoice-AnimalspeakVoice
D、AnimalspeakWoof-AnimalspeakMiaow
答案
B
解析
本题考查虚函数的运用,本题中定义Dogd;Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行派生类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为B选项正确。
转载请注明原文地址:https://www.kaotiyun.com/show/MKyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列语句都是程序运行时的第1条输出语句,其中一条语句的输出效果与其他三条语句不同,该语句是()。A)cout<<internal<<12345;B)cout<<left<<12345;C)cout<<right<<12345;D)c
如下函数的作用是以双倍行距输出文件: void double_space(ifstream& f, ofstream& t){ char c; while (______) { ______;
有如下程序:#include#includeusingstd::cout;classPoint{public:frienddoubledistance(constPoint&p);//
若MyClass为一个类,执行“MyClassa[4],*p[5];”语句时会自动调用该类构造函数的次数是
有如下程序: #include<iostream> using namespace std; class BASE { public: ~BASE(){cout<<"BASE";} }; cl
以下叙述正确的是
使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错,请改正其中的错误,使程序正确运行,并且使程序输出的结果为:30130注意:错误的语句在//*****error******的下面,修改该语句即可。#
使用VC6打开考生文件夹下的源程序文件modil.cpp。本程序要求输入一字符串,然后将其中的小写字母改变成大写字母,字符可能输入多行,当输入字符“?”时,默认字符输入结束,最后把结果输出到界面。注意:不要改动main函数,不能增行或删行,也不能
下列关于类模板的模板参数的叙述中,错误的是()。
下列字符串中可以用作C++标识符的是()。
随机试题
列宁说:“没有‘人的感情’,就从来没有也不可能有人对于真理的追求。”对于完善人的道德品质来说,这主要强调的是
ItwasattheSpringFestival______weparceledupsomebooksandtoystotaketotheChildren’sHome.
建设工程监理投标文件编制的依据包括()。
MysisterandIgrewupinalittlevillageinEngland.Ourfatherwasastruggling【C1】______,butIalwaysknewhewasspecial.
设是f(x)的一个原函数,则
一个校园网主干网有4台Catelyst6500核心交换机SW1~SW4,它们的优先级值依次为8192、24576、20480和16384,要将SW4作为根交换机,SW4优先级的正确配置是()。
已知过程对应的代码如下:SubProc()n=1f1=0f2=1DoWhilen<-8f=f1+f2Debug.Printff1==f2f2=fn=
HowmanyblackworkersdoesSouthAfrica’sNationalUnionofMineworkersrepresent?
Thefinancialanalysisprojecthastobefinishedby
A、Sueonlycametotwooftheparties.B、Suemissedmostoftheparties.C、Suehasbeentomostoftheparties.D、Suemissedall
最新回复
(
0
)