首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请打开考生文件夹下的解决方案文件proj2,其中有类Point(“点”)、Rectangle(“矩形”)和Circle(“圆”)的定义。在程序所使用的平面坐标系统中,x轴的正方向是水平向右的,Y轴的正方向是竖直向下的。请在横线处填写适当的代码并删除横线,以
请打开考生文件夹下的解决方案文件proj2,其中有类Point(“点”)、Rectangle(“矩形”)和Circle(“圆”)的定义。在程序所使用的平面坐标系统中,x轴的正方向是水平向右的,Y轴的正方向是竖直向下的。请在横线处填写适当的代码并删除横线,以
admin
2020-07-23
29
问题
请打开考生文件夹下的解决方案文件proj2,其中有类Point(“点”)、Rectangle(“矩形”)和Circle(“圆”)的定义。在程序所使用的平面坐标系统中,x轴的正方向是水平向右的,Y轴的正方向是竖直向下的。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应该是:
--圆形----------
圆心=(3,2)
半径=1
面积=3.14159
--外切矩形------
左上角=(2,1)
右下角=(4,3)
面积=4
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include<ioStream>
#include<cmath>
using namespace std;
//平面坐标中的点
//本题坐标系统中,x轴的正方向水平向右,y轴的正方向竖直向下。
class Point{
public:
Point(double x=0.0,doubley=0.0):x_(x),y_(y){}
double getX( )const{returnx;}
double getY( )const{return y;}
void setX(double x){x_=x;}
void setY(double y){y_=y;)
private:
double x_;//x坐标
double y_;//y坐标
};
class Rectanqle(
public:
Rectangle(Point p,intW,int h)
:point(P),width(W),height(h){}
double aEea( )const//矩形面积
{
return width*height;
}
Point topLeft( )const//左上角顶点
{
return point;
)
PointbottomRight( )const
//右下角顶点(注:y轴正方向竖直向下)
{
//*******found*******
return Point(_______);
}
private:
Point point;//左上角顶点
double width;//水平边长度
double height;//垂直边长度
};
//圆形
class Cirole{
public:
Circle(Point p,double r):center(p),radius(r){}
Rectangle boundingBox( )
conSt;
//外切矩形
double area( )const//圆形面积
{
//*******found*******
return PI*_______;}
public:
static const double PI;//圆周率
private:
Point center;//圆心
double radius;//半径
};
const double Circle::PI=3.14159;
RectangleCircle::boundingBOx
( )const
{
//*******found*******
Point pt(_______);
int w,h;
//*******found*******
w=h=_______;
return Rectangle(pt,w,h);
)
int main( )
{
Point p(3,2);
Circle c(p,1);
cout<<"--圆形--------\n";
cout<<"圆心=("<<P.getX( )<<’,’<<p.getY( )<<")\n";
cout<<"半径="<<1<<endl;
cout<<"面积="<<c.area( )<<endl<<endl;
Rectangle bb=c.boundingBox( );
Point t1=bb.topLeft( );
Point br=bb.bottomRight( );
cout<<"--外切矩形---------\n";
cout<<"左上角=("<<t1.getX( )<<’,’<<t1.getY( )<<")\n";
cout<<"右下角=("<<br.
getX( )<<’,’<<br.getY( )<<")\n";
cout<<"面积="<<bb.area( )<<endl;
return0;
}
选项
答案
(1)point.getX( )+width,point.getY( )+height (2)radius*radius (3)center.getX( )-radius,center.getY( )-radius (4)2*radius
解析
(1)主要考查考生对成员函数的掌握,程序要求返回右下角顶点,该点的x坐标为左上角顶点的x坐标加上width,该点的y坐标为左上角顶点Y坐标加上height,即return Point(point.getX( )+width,point.getY( )+height);。
(2)主要考查考生对成员函数的掌握,程序要求计算圆形面积,也就是返回圆面积,即return PI*radius*radius;。
(3)主要考查考生对成员函数的掌握,首先看函数声明:Rectangle Circle::boundingBox( )const,可知该函数要返回的是一个Rectangle类型,即要返回的是圆的外切矩形。再看Rectangle类的构造函数Rectangle(Point p,int w,int h),由此可知,空格处要定义的点pt为左上角点,即Point pt(center.getX( )-radius,center.getY( )-radius);。
(4)由函数声明和Rectangle类的构造函数可知,w和h应该为直径,即w=h=2*radius;。
转载请注明原文地址:https://kaotiyun.com/show/PQyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下类定义:classCup{public:_______________//构造函数声明private:doubleprice;
有如下程序:#includeusingnamespacestd;classMyClass{public:MyClass(inti=0){cout
有如下程序:#includeusingnamespacestd;intfun1(intx){return++x;}intfun2(int&x){re
下列叙述中正确的是( )。
软件按功能可以分为:应用软件、系统软件和支撑软件(或工具软件)。下面属于应用软件的是( )。
下列选项中属于面向对象设计方法主要特征的是( )。
下面不属于软件需求分析阶段主要工作的是
在E-R图中,用来表示实体的图形是()。
随机试题
“防消结合”,要求把同火灾做斗争的两个基本手段——防火和灭火有机地结合起来,做到相辅相成、互相促进。()
下列对于供配电线路的描述中,正确的有()。
按照《中国共产党章程》的规定,中国共产党是()
甲股份有限公司(以下简称甲公司)适用的所得税税率为33%,按净利润的10%提取法定盈余公积,按净利润的10%提取法定公益金。甲公司20×1年度的财务会计报告批准报出口为20×2年3月10日。甲公司发生的有关事项如下:1.20×1年11月10日,甲公司因对
旅客或者其继承人向铁路运输企业请求赔偿的请求,应当自事故发生之日起()内提出。
(单选)河姆渡氏族遗址发现于()。
①这些霜花团团簇簇的,很有点花园的气象②一旦太阳从山峦中升起来,印着霜花的玻璃窗就像魔镜一样,散发出奇诡的光辉③早晨,迎接我的是一夜寒流和冷月,以及凝结在玻璃窗上的霜花④这天的霜花不似往日的,总是呈树的形态⑤想必霜花也知道立春了吧⑥你能从中看出喇
对于ODS体系,有下列说法:Ⅰ.ODSⅠ:第一类ODS数据更新频率是天级,一般隔夜后将数据更新到ODS中Ⅱ.ODSⅡ:第二类ODS的数据更新频率是小时级,如4小时更新一次Ⅲ.ODSⅢ:第三类ODS的数据更新频率是秒级,即操作型系统中的数据发生改变后,
Whereisthewomangoingtospendherholiday?
Lookatthenotes.Someinformationismissing.Youwillhearpartofatalkbyaninvestmentconsultantofacompany.Foreach
最新回复
(
0
)