#include <iostream>
#include <cmath>
using namespace std;
class Trigle
{
public:
void Setabc (float x,float y, float z);
void Getabc (float *x,float *y, float *z);
float Perimeter (void);
float Area (void);
private:
float a, b, c;
};
void main(void)
{
Trigle Tri1;
Tri1.Setabc (4,5,6);
float x,y,z;
Tri1.Getabc (&x,&y,&z);
cout<<"三条边为:"<<x<<'\t'<<y<<'\t'<<z<<endl;
cout<<"三角形周长为:"<<Tri1.Perimeter()<<'\t'<<"面积:"<<Tri1.Area()<<endl;
}
void Trigle::Setabc (float x,float y, float z)
{
do
{
cin>>x>>y>>z;
a=x;
b=y;
c=z;
if ( a+b>c && a+c>b && b+c>a)
break;
}while (1);
}
void Trigle::Getabc (float *x,float *y, float *z)
{
*x=a;
*y=b;
*z=c;
}
float Trigle::Perimeter (void)
{
int sum;
sum=a+b+c;
return sum;
}
float Trigle::Area (void)
{
float p,s,m;
p=(a+b+c)/2;
s=p*(p-a)*(p-b)*(p-c);
m=sqrt(s);
return m;
}
设计一个三角形类
最新推荐文章于 2022-01-25 23:44:19 发布