设计一个三角形类要求:1、足够的可以描述三角形的数据、函数成员.2、用成员函数判断两个三角形是否相似.3、重载操作符“=

3个回答

  • #include

    using namespace std;

    class Triangle

    {

    public:

    Triangle(double a,double b,double c);

    bool similar(Triangle &t);

    bool operator = (Triangle &t);

    void set(double a,double b,double c);

    // void get(double &a,double &b,double &c);

    private:

    double a,b,c;

    double ja,jb,jc;

    };

    Triangle::Triangle(double a,double b,double c)

    {

    this->a=a;

    this->b=b;

    this->c=c;

    this->ja=arccos ((b^2+c^2-a^2)/(2*b*c));

    this->jb=arcos((a^2+c^2-b^2)/(2*a*c));

    this->jc=arcos((a^2+b^2-c^2)/(2*a*b));

    }

    bool Triangle::similar(Triangle &t)

    {

    double x[3]={t.ja,t.jb,t.jc};

    double y[3]={this->ja,this->jb,this->jc};

    int i,j;

    double temp;

    for(i=0; iy[j])

    {

    temp=y[i];

    y[i]=y[j];

    y[j]=temp;

    }

    }

    }

    if((x[0]/y[0]-x[1]/y[1]b,this->c};

    int i,j;

    double temp;

    for(i=0; iy[j])

    {

    temp=y[i];

    y[i]=y[j];

    y[j]=temp;

    }

    }

    }

    if((x[0]-y[0]c=c;

    this->ja=arccos ((b^2+c^2-a^2)/(2*b*c));

    this->jb=arcos((a^2+c^2-b^2)/(2*a*c));

    this->jc=arcos((a^2+b^2-c^2)/(2*a*b));

    }

    void Triangle::get(double &a,double &b,double &c)

    {

    a=this->a;

    b=this->b;

    c=this->c;

    }

    int main()

    {

    Triangle t1(1,2,2),t2(1,1,1.414);

    if(t1.similar(t2))

    {

    cout