# 如何用类里面的judgement函数判断三个点是否可以组成三角形

0

#include<iostream>
#include<math.h>
using namespace std;
class triangle
{
public:
void settriangle(double nx1,double ny1,double nx2,double ny2,double nx3,double ny3);
void judgement(double x1,double y1,double x2,double y2,double x3,double y3);
void showc(double x1,double y1,double x2,double y2,double x3,double y3);
void shows(double x1,double y1,double x2,double y2,double x3,double y3);
private:
double x1,y1,x2,y2,x3,y3;

};
void triangle::settriangle(double nx1,double ny1,double nx2,double ny2,double nx3,double ny3)
{
x1=nx1;y1=ny1;x2=nx2;y2=ny2;x3=nx3;y3=ny3;
}
void triangle::judgement(double x1,double y1,double x2,double y2,double x3,double y3)
{
double a,b,c;
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
c=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
if(a+b<c||b+c<a||c+a<b)
cout<<"error! "<<endl;
}
void triangle::showc(double x1,double y1,double x2,double y2,double x3,double y3)
{
double a,b,c;
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
c=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
cout<<"Perimeter:"<<a+b+c<<",";
}
void triangle::shows(double x1,double y1,double x2,double y2,double x3,double y3)
{
double a,b,c,s;
a=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
b=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));
c=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
s=(a+b+c)/2;
cout<<"Area:"<<sqrt(s* (s - a) * (s - b) * (s - c))<<endl;

}
int main()
{
double x1,y1,x2,y2,x3,y3;
while(cin>>x1>>y1>>x2>>y2>>x3>>y3)
{
triangle ntriangle;
ntriangle.judgement(x1,y1,x2,y2,x3,y3);
ntriangle.showc(x1,y1,x2,y2,x3,y3);
ntriangle.shows(x1,y1,x2,y2,x3,y3);
}
return 0;
}

您需要登录以后才能回答，未注册用户请先注册