首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
使用VC6打开考生文件夹下的源程序文件modi3.cpp,要求编写一个CMyShape类,含有求面积求周长等纯虚函数。然后编写一个CMyRectangle类和CMyCircle类继承CMyShape,并实现求面积、求周长的两个函数。在main()i~数中测
使用VC6打开考生文件夹下的源程序文件modi3.cpp,要求编写一个CMyShape类,含有求面积求周长等纯虚函数。然后编写一个CMyRectangle类和CMyCircle类继承CMyShape,并实现求面积、求周长的两个函数。在main()i~数中测
admin
2017-09-20
23
问题
使用VC6打开考生文件夹下的源程序文件modi3.cpp,要求编写一个CMyShape类,含有求面积求周长等纯虚函数。然后编写一个CMyRectangle类和CMyCircle类继承CMyShape,并实现求面积、求周长的两个函数。在main()i~数中测试得到下面的结果:
在CMyShape类构函数造内
在CMyCircle类构造函数内
在CMyShape类构造函数内
在CMyRectangle类构造函数内
myCircle:Area=3 14.1 59 Girth=62.83 19
myRectangle:Area==900 Girth==120
具体要求如下:
(1)定义求面积纯虚函数,请在注释∥********1********之处添加适当的语句。
(2)定义求周长纯虚函数,请在注释∥********2********之处添加适当的语句。
(3)请在注释∥********3********和∥********4********之处添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
#include
#include
#define PI 3.1415926
clas S CMyPoint
{
public:
int x,y;
CMyPoint(int tx,int ty):
X(tx),Y(ty)f}
};
class CMyShape
{
public:
CMyShape(){cout<<“在CMyShape类构造函数内”<
∥********1********
∥********2********
protected:
};
class CMyCircle:public CmyShape
{
public:
CMyCircle(CMyPoint i,double
j):CMyShape(),arcCenter(i),
radius(j){
cout<<“在CMyCircle类构造函数内”<
}
double GetArea()
{
return PI*radius*radius ;
}
double GetGirth()
{
return 2*PI*radius;
}
private:
CMyPoint arcCenter;
double radius;
};
class CMyRectangle:public
CmyShape
{
public:
CMyRectangle(CMyPoint
it,CMyPoint rb):leftTop(it),
rightBottom(rb),CMyShape(){
cout<<“在CMyRectangle类构造函数内”<
}
Double GetArea()
{
Int width=abS
(rightBottom.x—leftTop.x);
int height=abs
(rightBottom.y—leftTop.y);
Return width*height;
}
double GetGirth()
{
int width=abS
(rightB0ttom.X—leftTop.x);
int height=abs
(rightBottom.y—leftTop.y);
return 2*(width+height);
}
private:
CMyPoint leftTop,rightBottom;
};
void main()
{
CMyShape *myShape=NULL;
CMyCircle *myCircle=new
CMyCircle(CMyPoint(5,5),10);
CMyRectangle*myRectangle=
new CMyRectangle(CMyPoint(0,0),CMyPoint(30,30));
∥********3********
cout<<“myCi rcle:”<<“Area=”
<
GetArea()<<“\t”
<<“Girth=”<
GetGirth()<
∥********4********
cout<<”myRectangle:”<<”Are a=“<
GetArea()<<“\t,,
<<“Girth=”<
GetGirth()<
}
选项
答案
(1)添加语句:virtual double GetArea()=0; (2)添加语句:virtual double GetGirth()=0; (3)添加语句:myshape=mycircle; (4)添加语句:myshape=myRectanqle;
解析
类CMyPoint含有成员变量x和y,抽象基类CMyShape含有两个虚函数GetArea0和GetGirth0,分别用来求图形的面积和周长。类CMyRectangle和类CMyCircle派生于类CMyShape,并都实现了抽象父类的纯虚函数,通过这两个函数可分别求得矩形的面积和周长以及圆的面积和周长。
转载请注明原文地址:https://kaotiyun.com/show/pUAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
对于常数据成员,下面描述正确的是
以下有关类与结构体关系的叙述不正确的是
下列关于软件设计基本原理的叙述中错误的是
设有如图所示的二叉树则对该二叉树前序遍历的结果是
下列程序的输出结果为2,请将程序补充完整。#include<iostream>usingnamespacestd;classBase{public:______voidfun(){cout<<
在面向对象程序设计中,从外面看只能看到对象的外部特征,而不知道也无须知道数据的具体结构以及实现操作的算法,这称为对象的______。
下列情况中,不会调用拷贝构造函数的是()。
下列关于成员函数特征的描述中,错误的是()。
非成员函数只有在声明为(),才能访问这个类的所有private成员。
fstream、ifstream和ofstream文件流类的成员函数______关闭文件。
随机试题
与产生联行往来密切相关的银行业务是()
必须经国家药品监督管理局批准才能使用的是
根据《土地管理法》规定,经县级以上人民政府依法批准,可以以划拨方式取得国有土地的有()。
反倾销中的“正常价格”是如何规定的?
海运进口商品需办理监视、残损鉴定、监视卸货、海损鉴定、验残等,由()向检验检疫机构提出申请。
在确定企业宗旨时,企业高层管理人虽要避免()。
Asregardssocialconventions,wemustsayawordaboutthewell-knownEnglishclasssystem.Thisisanembarrassingsubjectfor
角色过载冲突是指一个人的角色要求太多,工作量太大,不可能完成所有角色所要求的工作时所面临的冲突。根据上述定义,下列属于角色过载冲突的是()。
根据所给资料,回答以下问题2015年全年Z省农林牧渔业增加值达到2982.66亿元,按可比价格计算,比上年增长4.7%,增速与上年基本持平。粮食种植面积425.84万公顷,比上年增加7.83万公顷;棉花种植面积41.56万公顷,减少5.73万公顷;油料种
HowtoCommunicateEffectivelyGeneralinformationoncommunication—It’saskillyoucanlearn.—Communicationsison
最新回复
(
0
)