#include <iostream>
#include <Cmath>
using namespace std;
class CPoint
{
private:
double x;
double y;
public:
CPoint(double xx=0,double yy=0);
double distance(CPoint p) const;
void input();
void output();
};
class CTriangle
{
public:
CTriangle(CPoint &X,CPoint &Y,CPoint &Z):A(X),B(Y),C(Z){} //给出三点的构造函数
void setTriangle(CPoint &X,CPoint &Y,CPoint &Z);//
double perimeter(void);//计算三角形的周长
double area(void);//计算并返回三角形的面积
bool isRightTriangle(); //是否为直角三角形
bool isIsoscelesTriangle(); //是否为等腰三角形
private:
CPoint A,B,C; //三顶点
};
CPoint::CPoint(double xx,double yy)
{
x=xx;
y=yy;
}
void CPoint::input()
{
char ch;
cout<<"请输入坐标点(格式x,y ):";
while(1)
{
cin>>x>>ch>>y;
if (ch==',') break;
cout<<"输入的数据格式不符合规范,请重新输入\n";
}
}
void CPoint::output()
{
cout<<"("<<x<<", "<<y<<")"<<endl;
}
double CPoint::distance(CPoint p) const
{
double d;
d=sqrt((p.x-x)*(p.x-x)+(p.y-y)*(p.y-y));
return d;
}
void CTriangle::setTriangle(CPoint &X,CPoint &Y,CPoint &Z)
{
A=X;
B=Y;
C=Z;
}
double CTriangle::perimeter(void)
{
double a=B.distance(C),b=C.distance(A),c=A.distance(B);
return (a + b + c);
}
double CTriangle::area(void)
{
double a=B.distance(C),b=C.distance(A),c=A.distance(B);
double s = (a + b + c) / 2;
return sqrt(s * (s - a) * (s - b) * (s - c));
}
bool CTriangle::isRightTriangle()
{
double a=B.distance(C),b=C.distance(A),c=A.distance(B);
double max=a;
if(b>max) max=b;
if(c>max) max=c;
if(((max==a)&&(a*a-b*b-c*c==0))||((max==b)&&(b*b-a*a-c*c==0))||((max==c)&&(c*c-b*b-a*a==0)))
return true;
else
return false;
}
bool CTriangle::isIsoscelesTriangle()
{
double a=B.distance(C),b=C.distance(A),c=A.distance(B);
if((a-b==0)||(b-c==0)||(c-a==0))
return true;
else
return false;
}
int main()
{
CPoint X(3,3),Y(4,4),Z(3,2);
CTriangle Tri1(X,Y,Z);
cout<<"该三角形的周长为:"<<Tri1.perimeter()<<",面积为:"<<Tri1.area()<<endl<<endl;
cout<<"该三角形"<<(Tri1.isRightTriangle()?"是":"不是")<<"直角三角形"<<endl;
cout<<"该三角形"<<(Tri1.isIsoscelesTriangle()?"是":"不是")<<"等腰三角形"<<endl;
return 0;
}