#include <iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
Triangle();//此句一定要有
Triangle(float x,float y ,float z ):a(x),b(y),c(z){}
float Perimeter(void);
float Area(void);
void ShowMessage();
private:
float a,b,c;
};
Triangle::Triangle()
{
a=1;
b=1;
c=1;
}
void Triangle::ShowMessage()
{
cout<<"三角形的三边长分别为:"<<a<<'\t'<<b<<'\t'<<c<<endl;
cout<<"该三角形的周长为:"<<Perimeter()<<'\t'<<"面积为:"<<Area()<<endl; //函数名前不用再加T1,因为主函数中已经有了。
}
void main(void)
{
Triangle T1;
T1.ShowMessage();
Triangle T2(3,4,5);
T2.ShowMessage();
}
float Triangle::Perimeter(void)
{
float l;
l=a+b+c;
return l;
}
float Triangle::Area(void)
{
float p,m;
m=(a+b+c)/2;
p=sqrt(m*(m-a)*(m-b)*(m-c));
return p;
}


被折叠的 条评论
为什么被折叠?



