三角形のクラス、座標

3531 ワード

/*
*Corpyright (c)2013,         
*All right reseved.
*  :   
*    :2014 4 1 
*   :v1.0
*    :
*    :    !const      
*    :
*    :
*    :
*/

#include <iostream>
#include <cmath>
using namespace std;
class CPoint
{
private:
  double x;  //    
  double y;  //    
public:
  CPoint(double xx=0,double yy=0)
  {
    x=xx;
    y=yy;
 }
  void input(double,double);
  double Distance1(CPoint p) const;   //        (      ,      p)
  CPoint SymmetricAxis(char style) const;//style 'x','y' 'o'     x , y ,     
};
class CTriangle
{
public:
  CTriangle(CPoint &X,CPoint &Y,CPoint &Z):A(X),B(Y),C(Z){} //         
  void setTriangle(CPoint &X,CPoint &Y,CPoint &Z);//
  float perimeter(void);//        
  float area(void);//           
  bool isRightTriangle(); //        
  bool isIsoscelesTriangle(); //        
private:
  CPoint A,B,C; //   
  double s1,s2,s3;
};
float CTriangle::perimeter(void)//        
{
    float s;
    s1=A.Distance1(B);
    s2=B.Distance1(C);
    s3=C.Distance1(A);
    s=s1+s2+s3;
    return s;
}
bool CTriangle::isIsoscelesTriangle()
{
    bool f=false;
    if(s1==s2||s2==s3||s3==s1)
        f=true;
    return f;
}
bool  CTriangle::isRightTriangle()
{
    bool f=false;
    if(s1*s1+s2*s2==s3*s3||s1*s1+s3*s3==s2*s2||s3*s3+s2*s2==s1*s1)
        f=true;
    return f;
}
float CTriangle::area(void)
{
    float s,q;
    s1=A.Distance1(B);
    s2=B.Distance1(C);
    s3=C.Distance1(A);
    q=(s1+s2+s3)/2;
    s=sqrt(q*(q-s1)*(q-s2)*(q-s3));
    return s;
}

void CPoint::input(double a,double b)
{
    x=a;
    y=b;
}
double CPoint::Distance1(CPoint p) const
{
    double s;
    s=sqrt((x-(p.x))*(x-(p.x))+(y-(p.y))*(y-(p.y)));
    return s;
}
void CTriangle::setTriangle(CPoint &X,CPoint &Y,CPoint &Z)
{
    X.input(0,0);
    A=X;
    B=Y;
    C=Z;

}
int main()
{
    CPoint s1,s2,s3;
    double a1,a2,a3,a4,a5,a6;
    cout<<"          "<<endl;
    cin>>a1>>a2;
    cout<<"          "<<endl;
    cin>>a3>>a4;
    cout<<"          "<<endl;
    cin>>a5>>a6;
    s1.input(a1,a2);
    s2.input(a3,a4);
    s3.input(a5,a6);
    CTriangle t1(s1,s2,s3);
    bool f1=false,f2=false;
    cout<<"       :"<<t1.perimeter()<<endl;
    cout<<"       :"<<t1.area()<<endl;
    f1=t1.isRightTriangle();
    if(f1==true)
    {
        cout<<"      !"<<endl;
    }
    else
    {
         cout<<"       !"<<endl;
    }
    f2=t1.isIsoscelesTriangle();
    if(f2==true)
    {
        cout<<"      !"<<endl;
    }
    else
    {
        cout<<"       !"<<endl;
    }

    return 0;
}

 
悟る
どんどん進歩しています!