首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类Rectangle和Circle的声明,二者都有计算对象面积的函数GetArea()和计算对象周长的函数GetPerim()。
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中包含抽象类Shape的声明,以及在此基础上派生出的类Rectangle和Circle的声明,二者都有计算对象面积的函数GetArea()和计算对象周长的函数GetPerim()。
admin
2020-07-23
43
问题
请使用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全国计算机二级
相关试题推荐
有如下类声明和函数声明classBase{intm;public:intn;protected:intp;};classDer
对长度为n的线性表排序,在最坏情况下,比较次数不是n(n-1)/2的排序方法是( )。
某二叉树有5个度为2的结点,则该二叉树中的叶子结点数是( )。
设变量x和y为整型变量,若有函数调用为"fun(&x,&y)",则下列选项中,能够作为函数fun原型声明的是
下面描述中错误的是( )。
下列有关继承和派生的叙述中,正确的是()。
下列叙述中正确的是
下列关于C++流的表述中,正确的是
计算机软件包括
有两个关系R,S如下:由关系R通过运算得到关系S,则所使用的运算为( )。
随机试题
微分方程x2y"+xy’+2y=0的阶是().
A、1.5~2.0mmB、0.8~1.2mmC、0.1~0.2mmD、0.5~1.0mmE、0.05~0.08mm一般情况下金属烤瓷全冠的唇面瓷层厚度应是
A.附子理中丸B.济生肾气丸C.都气丸D.左归丸E.右归丸治疗虚劳脾阳虚证,应首选
《传染病防治法》规定应予以隔离治疗的是
企业法人情况是银行选择合作伙伴的重要参考因素,银行在选择合作伙伴时,必须对企业法人代表的()等情况进行了解。
—Hergrandfatherhasalotofmoney.—______Shewouldn’tthinkaboutitevenifitwereoffered.
查询以字母N或O或P开头的字符串,正确的是
Inmanycountries,teenagersunder18yearsoldcandrivecars.Herearisesthequestion:Isitthebestwaytoimproveroadsaf
Amancannotbereallyhappyifwhatheenjoysdoingisignoredbysocietyasofnoimportance.
Beforeinvestingincommonstocks,oneshouldbeawareofboththeiradvantagesanddisadvantages.Oneadvantageistheirhighp
最新回复
(
0
)