64,651
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
#include<cmath>
using namespace std;
class point
{
public:
int x,y;
point(int xx=0,int yy=0)
{
x=xx;
y=yy;
}
point(point &p)
{
x=p.x;
y=p.y;
}
int getx()
{
return x;
}
int gety()
{
return y;
}
};
class Line
{
point p1,p2;
public:
Line():p1(1,2),p2(3,4)
{
}
Line(point &p3,point &p4)
{
p1=p3;
p2=p4;
}
};
class Triangle
{
Line l1,l2,l3;
double x,y,z;
public:
Triangle(point p1,point p2,point p3,point p4,point p5,point p6)
{
x=sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)*1.0);
y=sqrt((p3.x-p4.x)*(p3.x-p4.x)+(p3.y-p4.y)*(p3.y-p4.y)*1.0);
z=sqrt((p5.x-p6.x)*(p5.x-p6.x)+(p5.y-p6.y)*(p5.y-p6.y)*1.0);
}
double area()
{
if((x+y)>z&&(x+z)>y&&(y+z)>x)
return sqrt((x+y+z)*(x+y-z)*(x+z-y)*(z+y-x))/4;
else
return 0;
}
void show()
{
int i;
i=area();
if(i==0)
cout<<"三边不能构成三角形"<<endl;
else
cout<<area()<<endl;
}
};
void main()
{
int a,b,c,d,e,f;
cin>>a>>b>>c>>d>>e>>f;
Triangle T(a,b,c,d,e,f);
T.show();
}
如有问题欢迎继续追问,没问题请及时结贴,谢谢