#include <iostream>
#include <cmath>
using namespace std;
class Triangle
{
public:
void setABC(double x,double y,double z);
double perimeter();
double area();
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;
tril.setABC(4,5,6);
cout<<"三角形的周长为:"<<tril.perimeter()<<'\t'<<"面积为"<<tril.area()<<endl;
return 0;
}
运行结果: