#include<iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
void setABC(double x,double y,double z)
{
if(z<x-y || z>x+y)
cout<<"输入错误!"<<endl;
}
void getABC(double *x,double *y,double *z)
{
a=*x;
b=*y;
c=*z;
}
double perimeter(){return a+b+c;}
double area()
{
double l;
l=a+b+c;
return sqrt(l*(l-a)*(l-b)*(l-c));
}
private:
double a,b,c;
};
int main()
{
Triangle tri1;
tri1.setABC(4,5,6);
double x,y,z;
tri1.getABC(&x,&y,&z);
cout<<"三条边为:"<<x<<'\t'<<y<<'\t'<<z<<endl;
cout<<"三角形的周长为:"<<tri1.perimeter()<<'\t'<<"面积为:"<<tri1.area()<<endl;
return 0;
} |
|