首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式d=现的,三
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式d=现的,三
admin
2017-02-21
16
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式d=
现的,三角形面积的计算是按公式f=
了可实现的,其中s=
。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:
Side 1:9.43398
Side 2:5
Side 3:8
area:20
注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”
#include<iostream>
#include<cmath>
using namespace std;
class Point {//坐标点类
public:
const double x,y;
Point(double x=0.0,doubley=0.0):x(x),y(y){}
//**********found**********
double distanceTo(_______)const{
//到指定点的距离
return sqrt((x-P.x)*(x-p.x)+(y-P.y)*(y-P.y));
}
};
class Line{//线段类
public:
const Point p1,p2;//线段的两个端点
//**********found**********
Line(Point p1,Point p2):_______{}
double length()const{return
p1.distanceTo(p2);)//线段的长度
};
class Triangle{//三形类
public:
const Point p1,rp2,p3;//三角形的三个顶点
//**********found**********
Triangle(_______):p1(p1),p2(p2),p3(p3){}double lengthl()const{//边p1,p2的长度
return Line(p1,p2).length
();
}
double length2()const{//边p2,p3的长度
return Line(p2,p3).length
();
}
double length3()const{//边p3,p1的长度
return Line(p3,p1).length
();
}
double area()const{//三角形面积
//**********found**********
double s=_______;
return sqrt(s * (s-length1()) * (s-length2()) * (slength3()));
}
};
int main(){
Triangle r(Point(0.0,8.0),
Point(5.0,0.0),Point(0.0,0.0));
cout<<"Side 1:"<<r.length1()<<end1;
cout<<"Side 2:"<<r.length2()<<end1;
cout<<"Side 3:"<<r.length3()<<end1;
cout<<"area:"<<r.area()<<end1;
return 0;
}
选项
答案
(1)const Point& p (2)p1(p1),p2(p2) (3)Point p1,Point p2,Point p3 (4)(lengthl()+length2()+length3())/2
解析
(1)主要考查考生对函数形参的掌握,由函数的注释可知有本坐标点到达某个坐标点类的距离,再根据函数体return sqrt((x-p.x)*(x-p.x)+(y-p.y)*(y-p.y));可知,该坐标点类名为p,因此可以知道形参为Point&p,为了不改变该坐标点的值,前面要加上const。
(2)主要考查考生对构造函数的掌握,对于常变量型私有成员const Point p1,p2,只能用成员初始化列表进行赋值。
(3)主要考查考生对构造函数的掌握,由空格后面的语句:p1(p1),p2(p2),p3(p3){}可知,该构造函数需要进行成员列表初始化,再看类的私有成员const Point p1,p2,p3,可知p1,p2,p3是Point类型,因此形参为Point p1,Point p2,Point p3。
(4)主要考查考生对成员函数的掌握,根据函数注释,可知本函数要求计算三角形面积,再看题目的提示:s=(a+b+c)/2。可知空格处要填的是三角形的三条边之和除以2,而求边长的函数已经给出,这里直接调用即可。
转载请注明原文地址:https://kaotiyun.com/show/Q6Ap777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下语句,则对a数组元素的引用不正确的是(0≤i≤9)inta[10]={0,1,2,3,4,5,6,7,8,9},*p=a;
以下哪个特征不是面向对象思想中的主要特征?
虚函数必须是类的【】。
有如下类定义:classSample{public:Sample();~Sample();private:staticintdata;};将静态数据成员data初始化为0的语句是【】。
下列关于队列的叙述中正确的是
以下选项中合法的实型常数是
写出执行完下列代码段之后指定变量的值:boolx=true,y=false,z=false;x=x&&y||z;y=x||y&&z;z=!(x!=y)||(y==z);则x=false,y=false,Z=
模板使我们可以用一个代码段指定一组相关函数(称为______)或一组相关类(称为______。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*cp的值是()。
如果有以下定义及初始化:inta=3,*p=&a;则由此可以推断,*p的值是()。
随机试题
MRI诊断价值相对较低的疾病是
关于诉前权利保全应符合的条件表述错误的是()
______attemperaturesabove1,250°C,clayfusesandbecomesnonporousstonewareorporcelain.
人工成本包括的内容有()。
市场营销数据库对于高质量地完成直复营销活动,具有的优势有()。
如图6(a)所示,圆形线圈P静止在水平桌面上,其正上方悬挂一相同的线圈Q,P和Q共轴,Q中通有变化电流,电流随时间变化的规律如图6(b)所示,P所受的重力为G.桌面对P的支持力为N,则()。
感觉对比,是指同一感受器接受不同刺激而使得感受性发生变化的现象。下列属于感觉对比范畴的是()。
[*]
Whendoesthesongbirdperformatapdance?
Americansbelievethatindividualsmustlearnto【B1】_______themselvesorrisklosingfreedom.Thismeansachievingbothfinanci
最新回复
(
0
)