首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式d=实现的,
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式d=实现的,
admin
2018-06-19
27
问题
请使用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,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 length1( )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())*(s-length3()));
}
};
int main(){
Triangle r(Point(0,0,8.0),Point(5.0,0.0),Point(0.0,0.0));
cout<<"Side 1:"<<r.lengthl()<<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)pl(p1),p2(p2) (3)Point p1,Point p2,Point p3 (4)(length1( )+length2( )+length3( ))/2
解析
(1)主要考查考生对函数形参的掌握,由函数的注释可知有本坐标点到达某个坐标点类的距离,再根据函数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,P0int p2,Point p3。
(4)主要考查考生对成员函数的掌握,根据函数注释,可知本函数要求计算三角形面积,再看题目的提示:s=(a+b+c)/2。可知空格处要填的是三角形的三条边之和除以2,而求边长的函数已经给出,这里直接调用即可。
转载请注明原文地址:https://kaotiyun.com/show/jNAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若有以下程序:#include<iostream>usingnamespacestd;voidsub(intx,inty,int*z){*z=y+x;}intmain(){inta,b,c;sub[8
下列程序输出的结果是()。#include<stdio.h>fun1(chara,charb){charc;c=a;a=b;b=c;}fun2(char*a,charb){charc;c=*a;*a=b;b=c;}
如下程序声明了一个电话号码类PhoneNumber,重载了流插入运算符<<,以便于电话号码的输出。请将程序补充完整。#include<iostream>#include<iomanip>#include<string>using
与成员访问表达式p->name等价的表达式是______。
设有下定义的语句:inta[3][2]={10,20,30,40,50,60};intb[3][2]={10,20,30,40,50,60};则a[1][1]*b[2][1)的结果为()。
在下面程序的画线处填上适当的内容,使程序执行后的输出结果为1/2005。#include<iostream>usingnamespacestd;classDate{public:Date(intm
软件需求分析阶段的工作,可以分为4个方面:需求获取、需求分析、编写需求规格说明书以及()。
在结构化设计方法中,生成的结构图(SC)中,带有箭头的连线表示
将关键字const写在函数头之后,函数体之前,说明该函数是一个const成员函数。此时const不是指定函数的返回值,而是修饰______指针。
在E-R图中,用来表示实体的图形是()。
随机试题
窦性心动过速首选用:
WHO健康权指
以下哪种行为属于抢劫罪的法定加重情形,应被判处10年以上有期徒刑、无期徒刑、死刑?()
下列属于疏散行动时间的是()。
张老师根据自己班级的情况,为解决班级内部班干部的人际关系问题,建立和谐融洽的班级氛围,自主开发了“和谐人际”的班级课程,这体现了教师()。
王、赵二人各以20%与80%的份额共有一问砖窑,出租给汪某,现王某欲将自己的份额转让,请问下列表述中哪一种说法是正确的?()
儿童对他人行为的归因受到_____________和_____________的影响。
求函数f(x)=ln(1-x-2x2)的幂级数,并求出该幂级数的收敛域.
CharlotteSalomon’sbiographyisareminderthatthecurrentsofprivatelife,howeverdiverted,dislodged,ortwistedby(i)___
Nowtheincomegapisgettingwiderandwider.Insomeprivatelyownedfirms,【B1】______,orforeign-fundedcompanies,an【B2】____
最新回复
(
0
)