首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
有如下程序: #include #include using namespace std; class Animal{ public: virtual string
admin
2020-06-29
39
问题
有如下程序:
#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、Dog speak Voice - Cat speak Voice
B、Dog speak Woof - Cat speak Miaow
C、Animal speak Voice - Animal speak Voice
D、Animal speak Woof - Animal speak Miaow
答案
B
解析
本题考查虚函数的运用,本题中定义Dog d; Type(d)时,执行类class的Type函数,输出Dog,然后输出speak,然后执行派生类的Speak函数输出Voice,最后输出-,同理cat输出类似,所以结果为B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/zZ8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的运行结果为()。#include<iostream.h>voidmain(){inta=2;intb=a+1;cout<<a/b<<endl;}
有如下程序:#include<iostream>usingnamespacestd;classONE{public:virtualvoidf(){cout<<"1";}};
下面关于C++语言的描述错误的是
下列叙述中正确的是
使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错误,请改正错误,使得程序输出:Hellotest注意:不要改动main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在//*****
下列关于C++函数的叙述中,正确的是()。
在C++程序中,如果要求通过函数来实现一种简单的功能,并且要求尽可能加快程序执行速度,则应该选用()。
在软件开发中,需求分析阶段产生的主要文档是( )。
数据库应用系统中的核心问题是( )。
设c1和c2是类MyClass的对象,若将前缀运算符"--"和运算符"/"作为类MyClass的友元函数重载,则表达式--c1/c2等价于
随机试题
Excel中,排序可以根据_______选择字段值的升序或降序两个方向分别进行。
女性成年患者,拟行阑尾炎切除术,术前常规禁饮时间不得少于()
下列不是沥青混凝土路面主要检验内容的是( )。
采用低正常股利加额外股利政策的优点有()。
下列交换方式中,()一次连接沿着一条路由路径发送所有的数据。
人工智能的出现对哲学意识论的意义是
旧唯物主义之所以是半截子的唯物主义,是因为( )
比较客观、公正、准确地评价社会成员人生价值的大小,除了要掌握科学的标准外,还需要掌握恰当的评价方法,坚持()
下列叙述中,正确的是()。
Ifpeoplecan’ttellallkindsofcolors,wecansaytheyarecolor-blind.Mostcolor-blindpeoplecansee【T1】______butcannott
最新回复
(
0
)