首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程文件proj3,此工程中包含一个源程序文件proj3.epp,其中定义了用于表示平面坐标系中的点的类MyPoint和表示矩形的类MyRectangle;程序应当显示: (0,2)(2,2
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程文件proj3,此工程中包含一个源程序文件proj3.epp,其中定义了用于表示平面坐标系中的点的类MyPoint和表示矩形的类MyRectangle;程序应当显示: (0,2)(2,2
admin
2019-06-05
44
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程文件proj3,此工程中包含一个源程序文件proj3.epp,其中定义了用于表示平面坐标系中的点的类MyPoint和表示矩形的类MyRectangle;程序应当显示:
(0,2)(2,2)(2,0)(0,0)4
但程序中有缺失部分,请按照以下提示,把缺失部分补充完整:
(1)在“//**1** ****found****”的下方是构造函数的定义,它用参数提供的左上角和右下角的坐标对up_left和down_right进行初始化。
(2)在“//**2** ****found****”的下方是成员函数getDownLeft的定义中的一条语句。函数getDownLeft返回用MyPoint对象表示的矩形的左下角。
(3)在“//**3** ****found****”的下方是成员函数area的定义,它返回矩形的面积。
注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“****found****”。
//proj3.cpp
#include<iostream>
using namespace std;
class MyPoint{//表示平面坐标系中的点的类
double x;
double y;
public:
MyPoint(double X,double y)
{this->x=x;this->y=y;)
double getX()const{return x;)
double getY()const{return y;)
void show()const{cout<<’(’
<<X<<’,’<<Y<<’)’;)
};
class MyRectangle {//示矩形的类
MyPoint up_left; //矩形的左上角顶点
MyPoint down_right;//矩彤的右下角顶点
public:
MyRectangle(MyPoint upleft,MyPoint downright);
MyPoint getUpLeft()const{return up_left;}//返回左上角坐标
MyPoint getDownRight()const
{return downright;}/返回右下角坐标
MyPoint getUpRight()const;
//返回右上角坐标
MyPoint getDownLeft()const;
//返回左下角坐标
double area()const; //返回矩形的面积
};
//**1** *********found*********
MyRectangle∷ MyRectangle
(_______):
up_left(p1),down_right(p2){}
MyPoint MyRectangle∷getUpRight
()const
{
return MyPoint(down_right.
getX(),up left.getY());
}
MyPoint MyRectangle∷ getDown
Left()const
{
//**2** *******found*******
return MyPoint(_______);
}
//**3** *******found*******
_______area()const
{
return(getUpLeft().getX()
-getDownRight().getX()) *
(getDownRight().getY()-getUpLeft().getY());
}
int main()
{
MyRectangle r(MyPoint(0,2),MyPoint(2,0));
r.getUpLeft().show();
r.getUpRight().show();
r.getDownRight().show();
r.getDownLeft().show();
cout<<r.area()<<end1;
return 0;
}
选项
答案
(1)MyPoint p1,MyPoint p2 (2)up_left.getX(),down_right.getY() (3)double MyRectangle∷
解析
(1)考查构造函数,构造函数中的参数要给私有成员赋值,在下句中up_left(p1),down_right(p2){}指出私有成员赋值要使用形参p1和p2,因此这里参数要定义为MyPoint p1,MyPoint p2。
(2)主要考查成员函数的返回语句,MyPoint MyRectangle∷getDownLeft()const函数要求返回一个左下角的点坐标,因此使用语句MyPoint(up_left.getX(),down_right.getY());。
(3)主要考查成员函数的定义,在MyRectangle类中已经声明double area()const,因此此处只要添加double MyRectangle∷即可。
转载请注明原文地址:https://kaotiyun.com/show/Gm8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列程序的输出结果为-5/8-3/4,请将横线处的缺失部分补充完整。#include<iostream>usingnamespacestd;classFraction{//"分数"类public:Fractio
C++系统预定了4个用于标准数据流的对象,下列选项中不属于此类对象的是()。A)coutB)cinC)cerrD)cset
下列关于模板的描述中,错误的是()。A)类模板的成员函数都是模板函数B)函数模板是一种参数化类型的函数C)满足一定条件时可以省略模板实参D)模板形参只能由关键字typename声明
下列关于二叉树的叙述中,正确的是()。A)叶子结点总是比度为2的结点少一个B)叶子结点总是比度为2的结点多一个C)叶子结点数是度为2的结点数的两倍D)度为2的结点数是度为1的结点数的两倍
请将下列类定义补充完整,横线处应填加语句__________。classTestClass{public:voidfun(){cout
设根结点的层次为0,高度为K的二叉树最最大结点数为()个。
关于运算符重载,下列表述中正确的是()。
有如下函数模板:templateTsquare(Tx){returnx*x;}其中T是()。
数据管理技术发展的三个阶段中,()没有专门的软件对数据进行管理。I.人工管理阶段Ⅱ.文件系统阶段Ⅲ.数据库阶段
已知inta,*pa=&a;输出指针pa十进制的地址值的方法是()。
随机试题
在临床放射治疗计划中关于等效生物剂量的考虑,下面说法错误的是
中枢性面瘫与周围性面瘫临床表现区别的关键是
与慢性阻塞性肺气肿发病有关的因素是
风邪初中经络,舌强不能语言。手足不能运动者,治宜选用
背景材料: 某桥梁3号墩为桩承式结构,承台体积约为200m3,承台基坑开挖深度为4m,原地面往下地层依次为:0~50cm腐殖土,50~280cm粘土,其下为淤泥质土,地下水位处于原地面以下l00cm。 根据该桥墩的水文地质,施工单位在基坑开
下列有关各单位预算管理职权的表述中,正确的有()。
由于交通堵塞,左老师上课迟到了,刚好班里有一名同学紧随其后。左老师诚恳地跟同学们道歉,并向全班同学保证,下次提前出门。迟到的同学受到鼓舞,也主动承认了错误。左老师主动向学生道歉的做法()。
经过长期的建设和培育,长沙市已初步形成了工程机械、汽车及零部件、电子信息、家用电器、中成药及生物医药、新材料六大产业集群。从集群规模看,六大产业集群资产占全部规模工业资产总额的46.9%。2009年1-5月实现工业总产值518.73亿元,占全部规模
重载的运算符保持其原有的【】、优先级和结合性不变。
【B1】【B6】
最新回复
(
0
)