#include<iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
Triangle(double x,double y,double z)
{
a=x;
b=y;
c=z;
}
double isTriangle()
{
if(a+b>c&&a+c>b&&b+c>a)
return true;
else
return false;
}
double getA()
{
return a;
}
double getB()
{
return b;
}
double getC()
{
return c;
}
double perimeter()
{
return a+b+c;
}
double area()
{
double t,w;
w=(a+b+c)/2;
t=w*(w-a)*(w-b)*(w-c);
return sqrt(t);
}
double showMessage()
{
Triangle Tri(7,8,9);
if(Tri.isTriangle())
{
cout <<"三条边为:"<<Tri.getA()<<','<<Tri.getB()<<','<<Tri.getC()<<endl;
cout << "三角形的周长为:" <<Tri.perimeter()<<'\t'<<"面积为:"<<Tri.area()<< endl;
}
else
cout<<"不能构成三角形"<<endl;
}
private:
double a,b,c;
};
int main()
{
Triangle Tri(7,8,9);
Tri.showMessage();
return 0;
}
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。