#include <iostream>
#include <cmath>
using namespace std;
class Triangle
{
public:
void setABC(double x,double y,double z);
double perimeter();
double area();
void setA(double x){a=x;}
void setB(double y){b=y;}
void setC(double z){c=z;}
double getA(){return a;}
double getB(){return b;}
double getC(){return c;}
bool isTriangle()
{
if(a+b > c && a+c > b && b+c > a)
return true;
else
return false;
}
private:
double a,b,c;
};
void Triangle::setABC(double x,double y,double z)
{
a=x;
b=y;
c=z;
}
double Triangle::perimeter()
{
return (a+b+c);
}
double Triangle::area()
{
double i;
i=(a+b+c)/2;
return (sqrt(i*(i-a)*(i-b)*(i-c)));
}
int main()
{
Triangle tril;
double x,y,z;
cout<<"请输入三角形三边:";
cin>>x>>y>>z;
tril.setA(x);
tril.setB(y);
tril.setC(z);
if(tril.isTriangle())
{
cout<<"三角形三边:"<<tril.getA()<<","<<tril.getB()<<","<<tril.getC()<<endl;
cout<<"三角形的周长为:"<<tril.perimeter()<<'\t'<<"面积为"<<tril.area()<<endl;
}
else
cout<<"不能构成三角形"<<endl;
return 0;
}
运行结果: