首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类Rectangle和Circle的声明,二者都有计算对象面积的函数GetArea()和计算对象周长的函数GetPerim()。
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类Rectangle和Circle的声明,二者都有计算对象面积的函数GetArea()和计算对象周长的函数GetPerim()。
admin
2020-07-23
70
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类Rectangle和Circle的声明,二者都有计算对象面积的函数GetArea()和计算对象周长的函数GetPerim()。程序中位于每个“//****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应该是:
TheareaoftheCircleis78.5
TheperimeteroftheCimleis31.4
TheareaoftheRectangleis24
TheperimeteroftheRectangleis20
注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
usingnamespacestd;
classShape
{
public:
Shape(){}
~Shape(){}
//**********found**********
________floatGetArea()=0;
//**********found**********
________floatGetPerim()=0;
};
classCircle:publicShape
{
public:
Circle(floatradius):itsRadius
(radius){}
~Circle(){}
floatGetArea(){return3.14*itsRadius*itsRadius;}
floatGetPerim()
{return6.28*itsRadius,}
private:
floatitsRadius;
};
classRectangle:publicShape
{
public:
//**********found**********
Rectangle(floatlen,floatwidth):
________{};
~Rectangle(){};
virtualfloatGetArea()
{returnitsLength*itsWidth;}
floatGetPerim()
{return2*itsLength+2*itsWidth;}
virtualfloatGetLength(){return
itsLength;}
virtualfloatGetWidth(){returnitsWidth;}
private:
floatitsWidth;
floatitsLength;
};
intmain()
{
//*****’k****found**********
sp=newCircle(5);
cout<<"TheareaOftheCircleis"
<
GetArea()<
cout<<"TheperimeteroftheCircleis"<
GetPerim()<
deletesp;
sp=newRectangle(4,6);
cout<<"TheareaoftheRectangleis"<
GetArea()<
cout<<"TheperimeteroftheRectangleis"<
GetPerim()<
deletesp;
return0;
}
选项
答案
(1)virtual (2)virtual (3)itsLength(len), itsWidth(width) (4)Shape* sp;
解析
(1)和(2)主要考查考生对纯虚函数定义的掌握,纯虚函数前要添加关键字virtual。
(3)主要考查考生对构造函数的掌握,使用成员列表初始化。
(4)主要考查考生对指针的掌握,由下一条语句:sp = new Circle(5),可知sp为Shape型指针。
转载请注明原文地址:https://kaotiyun.com/show/Snyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序#includeusingnamespacestd;classAA{charc;public:AA(charch):c(ch){cout
下列关于内联函数的叙述中,错误的是
下列叙述中,错误的是
要利用C++流进行文件操作,必须在程序中包含的头文件是
下列语句或语句序列中有语法错误的是
ClassA是一个类,且有如下语句序列ClassAc1,*c2;ClassA*c3=newMyClass;ClassA&c4=c1;则ClassA的构造函数被调用的次数是
字符串"8+a=\tb\n\r"的长度为
下列关于运算符重载的描述中,正确的是()。
有如下语句序列:charstr[10];cin>>str;当从键盘输入"Ilovethisgame"时,str中的字符串是()。
算法的空间复杂度是指()。
随机试题
伴有膀胱刺激症状及尿道和阴茎头部放射疼者,考虑为()
A.补心丹B.养心汤C.归脾汤D.炙甘草汤E.真武汤
在商业银行设立国别风险限额和确定国别风险准备金计提水平时,应充分考虑国别风险评级结果。()
边远地区和交通不便地区的开户单位的库存现金限额,可按多于5天、但不得超过10天的日常零星开支的需要确定。()
顾客对供方的质量体系要求往往需要证实,以使顾客具有足够的信任。证实的方法包括()。
报告作为上行文,发文字号的位置在()。
InBritain,TonyBlair’schieftaskistoWhatdoestheauthormeanby"aclassicnegotiatingerror"(Paragraph2)?
Onlytwocountriesintheadvancedworldprovidenoguaranteeforpaidleavefromworktocareforanewbornchild.Lastspring
Accountinginformationisexpressedprimarilyinmonetaryterms.Themonetaryunitistheprimemeansofmeasuringassets.This
AssistanttoPublicRelationsManagerBusinessPressistheworld’smostrespectedpublisherofbusinessnews.PRandpublici
最新回复
(
0
)