#include <iostream>
#include <cmath>
using namespace std;
class Triangle
{
public:
Triangle(double x,double y, double z):a(x),b(y),c(z){};
void showMessage();
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::showMessage()
{
cout << "三条边为:" << a << "," << b << "," << c << endl;
cout<<"三角形的周长为:"<<perimeter()<<'\t'<<"面积为"<<area()<<endl;
}
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 Tri(7,8,9);
Tri.showMessage();
return 0;
}
运行结果: