首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程中包含一个源程序文件main.cpp,其中有坐标点类Point、线段类Line和矩形类Rectangle的定义,还有main函数的定义。程序中两点间的距离的计算是按公式d=实现
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程中包含一个源程序文件main.cpp,其中有坐标点类Point、线段类Line和矩形类Rectangle的定义,还有main函数的定义。程序中两点间的距离的计算是按公式d=实现
admin
2015-06-27
14
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,此工程中包含一个源程序文件main.cpp,其中有坐标点类Point、线段类Line和矩形类Rectangle的定义,还有main函数的定义。程序中两点间的距离的计算是按公式d=
实现的。请在横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:
Width:4
Height:6
Diagonal:7.2111
are,a:24
注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
#include
usingnamespacestd;
classPoint{//坐标点类
public:
constdoublex,y;
Point(doublex=0.0,doubley=0.
0):x(x),y(y){)
//**********found**********
doubledistanceTo(________)
const{
//到指定点的距离
returnsqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));
}
};
classLine{//线段类
public:
constPointp1,p2;//线段的两个端点
Line(Pointp1,Pointp2):p1(p1),
p2(p2){)
//**********found**********
doublelength()const{returnp1.
________;)//线段的长度
};
classRectangle{//矩形类
public:
constPointupper_left;//矩形的左上角坐标
constPointdown_right;//矩形的右下角坐标
Rectangle(Pointpl,Pointp2):upperleft(p1),down_right(p2){}
doublewidth()const{//矩形水平边长度
//**********found**********
returnLine(upperLleft,________).
length();
}
doubleheight()const{//矩形垂直边长度
returnLine(upperleft,Point(upperleft.x,down_right.y)).length();
l
doublelengthOfDiagonal()const{
//矩形对角线长度
returnLine(upperleft,down_right).length();
}
doublearea()const{//矩形面积
//**********found**********
return________;
}
};
intmain(){
Rectangler(Point(1.0,8.0),Point(5.0,2.0));
cout<<"Width:"<
cout<<”Height:”<
cout<<”Diagonal:”<
Diagonal()<
cout<<”area:"<
return0;
}
选项
答案
(1)const Point& p (2)distanceTo(p2) (3)Point(down_right.x, upper_left.y) (4)width() * height()
解析
(1)主要考查考生对成员函数的掌握,根据函数体可知形参应为const Point& p。
(2)主要考查考生对成员函数的掌握,求线段的距离直接调用函数distanceTo即可。
(3)主要考查考生对成员函数的掌握,函数功能求矩形水平边长度,这里程序直接构造Line类型并调用length函数。
(4)主要考查考生对成员函数的掌握,矩形面积为高乘宽,因此,调用函数height和width取得高和宽。
转载请注明原文地址:https://jikaoti.com/ti/DkXiFFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
简述英法百年战争的起因和结果。(南京大学1996年世界古代中世纪史真题;东北师范大学1998年世界中古史真题;东北师范大学2000年世界通史真题;东北师范大学2002年世界史真题)
在随机区组实验设计中,总平方和可以被分解为()
得出两总体的样本数据如下:甲(33,18,40,50,54,30,39);乙(48,17,24,22,38)。在秩和检验中,秩和是()
简述教育性教学原则。
简述法律关系的定义和特征。
我国实体法和程序法开始逐步分离始于()
设函数U=f(χz,yz,χ)的所有二阶偏导数都连续,则=().
设某数据库中有旅客表A(旅客编号,城市)和旅客表B(旅客编号,城市),现将所有旅客的数据存储这两张表中。请补全如下查询语句,使得该查询语句能查询所有旅客所在的全部的不重复的城市。SELECT城市FROM旅客表A【14】SELECT城市FROM旅客表B
设要在表T上建立一个针对插入操作的前触发器,请补全下列语句:CREATETRIGGERtri_insertONT【6】INSERT
对下列二叉树进行中序遍历的结果是()。
随机试题
在Excel2003中,下列取值相同的表达式是__________。()
患者,男,36岁,因半年来右下第一磨牙咬合面深龋洞不能咬物而就诊。一周前已做一次垫底银汞充填,一天前出现自发痛,冷热痛持续,不能咬物。查:右下第一磨牙咬合面充填体完整,叩痛(+),冷测引起剧痛。
( )是规定要求已得到满足的客观证据的认证和提供。
500kV架空电力线路与VHF(I)频段电视差转台、转播台间的防护间距不应小于()。
()是评估无形资产使用频率最高的方法。
2,4,12,48,240,()
科学家在100亿光年外的星系里发现一颗超亮超新星,其爆发于宇宙大爆炸后约35亿年,正值天文学家所称的“宇宙正午”时期。普通超新星是大质量恒星死亡时发生剧烈爆炸产生的。超亮超新星的亮度比普通超新星高10到100倍,目前还不太清楚其形成机制。以往发现的超亮超新
随着社会现代化程度的不断提高、社会化分工日益精细,人与人之间的依赖程度也越来越高,人们的生活重心正逐渐由工作单位向社区转移。而就本质而言,人与人之间的互动关系构成了社区生活的主要内容。以下哪项,从上述题干中推出最为恰当?
从一组7个人——J,K,L,M,N,P和Q中恰好选出4个去参加某外交官的退休宴会。对出席人员的选择必须遵循以下条件:要么J被选,要么K被选,但两人不能同时被选;要么N被选,要么P被选,但两人不能同时被选;若N被选时,L肯定被选;
设D是由曲线y=sinx+1与三条直线x=0,x=π,y=0所围成的曲边梯形,求D绕x轴旋转一周所围成的旋转体的体积.
最新回复
(
0
)