10:Point_line_triangle_类的组合
查看提交统计提问
总时间限制: 5000ms 内存限制: 65536kB
描述
设计一个Point类,表示平面中的一个点
设计一个Line类,表示平面的一条线段
设计一个Triangle类(三角形类),内含三条边。
要求:
设计三个类的相应的构造函数、复制构造函数,完成初始化和对象复制
设计Triangle类的成员函数,分别完成三条边能否构成三角形的检查,三角形周长的计算
输入
三个点
输出
三角形的周长(保留小数点后三位数)。如果不能构成三角形,输出 no
样例输入
0 0
0 1
1 0
样例输出
3.414
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
class Point{
private:
int x,y;
public:
Point(int xx,int yy):x(xx),y(yy){}
friend class Line;
};
class Line{
private:
Point A,B;
public:
Line(int x1,int y1,int x2,int y2):A(x1,y1),B(x2,y2){}
double longth(){return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}//通过对象访问私有数据成员,不用通过共有函数去访问私有数据成员
friend class Triangl