首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式实现的,三角
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式实现的,三角
admin
2020-06-29
34
问题
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式
实现的,三角形面积的计算是按公式
实现的,其中
。请在程序中的横线处填写适当的代码,然后删除横线,以实现上述类定义。此程序的正确输出结果应为:
Side 1:9.43398
Side 2:5
Side 3:8
area:20
注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include
#include
using namespace std;
class Point{//坐标点类
public:
const double X,Y;
Point(double X=0.0,double Y=
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,p2,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—lengthl())*(S
—length2())*(S—length3()));
}
};
int main(){
Triangle r(Point(0.0,8.0),Point
(5.0,0.0),Point(0.0,0.0));
cout<<”Side 1:”<
end1
cout<<”Side 2:”<
end1;
cout<<”Side 3:”<
end1;
cout<<”area:”<
return 0;
}
选项
答案
(1)const Point&p (2)p1(p1),p2(p2) (3)Point p1,Point p2,Point p3 (4)(length1()+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)主要考查考生对构造函数的掌握,由空格后面的语句:pl(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/oa8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
当用数组元素作函数参数时,这属于【】传递。
有以下程序voidf(intx,inty){intt,if(x<y){t=x;x=y;t;}}main(){inta=4,b=3,c=5;f(a,B);f(a,C);f(b,C);cout<<a<<"
以下4个程序中,不能实现两个实参值进行交换的是()。
以下程序的输出结果是______。#include<iostream.h>#include<string.h>voidmain(){char*p1=",hello",*p2="world!",str[
有如下程序:#includeusingnamespacestd;intmain(){cout.fill(‘*’);cout.width(6);cout.fill(‘#’)
算法分析的目的是()。
为了使类中的某个成员不能被类的对象通过成员操作符访问,则不能把该成员的访问权限定义为
多继承的构造顺序可分为如下四步:①所有非虚基类的构造函数按照它们被继承的顺序构造②所有虚基类的构造函数按照它们被继承的顺序构造③所有子对象的构造函数按照它们声明的顺序构造④派生类自己的构造函数体这四个步骤
软件需求规格说明书应具有完整性、无歧义性、正确性、可验证性、可修改性等特性,其中最重要的是【 】。
随机试题
减少二氧化碳排放的途径主要有两条:改进能源结构和提高_______。
具有"温化痰饮"功用的方剂是
A、意识丧失是由于大脑半球弥散性损害B、意识丧失是由于广泛性发作脑功能紊乱C、意识丧失是由于上行网状结构供血不足D、意识丧失是由于广泛性一过性大脑供血不足E、意识丧失是由于间脑压迫性病变椎基底动脉供血不足
老年人患病的特点是
没有被剥夺政治权利的犯罪分子正在监狱服刑期间,有关其选举权的表述哪个是正确的?
下列对于强制性标准监督检查的表述,错误的是()。
改良土路堤填筑施工要求包括()。
2016年10月,习近平主席就加强和创新社会治理作出重要指示,强调要()。
查询“书名”字段中包含“等级考试”字样的记录,应该使用的条件是
根据域名代码规定,NET代表
最新回复
(
0
)