#include<iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
Triangle(double x=1,double y=1,double z=1)
{
a=x;
b=y;
c=z;
}
double perimeter();
double area();
void showMessage();
private:
double a,b,c;
};
void Triangle::showMessage()
{
cout<<"三条边为:"<<a<<' '<<b<<' '<<c<<endl;
cout<<"三角形的周长为:"<<perimeter()<<'\t'<<"面积为:"<<area()<<endl;
}
double Triangle::perimeter()
{
return a+b+c;
}
double Triangle::area()
{
double x=(a*a+b*b-c*c)/(2*a*b);
return (a*b*sqrt(1-x*x))/2;
}
int main()
{
Triangle Tri1;
Tri1.showMessage();
Triangle Tri2(1.5);
Tri2.showMessage();
Triangle Tri3(1.5,1.5);
Tri3.showMessage();
Triangle Tri4(7,8,9);
Tri4.showMessage();
return 0;
}
#include<cmath>
using namespace std;
class Triangle
{
public:
Triangle(double x=1,double y=1,double z=1)
{
a=x;
b=y;
c=z;
}
double perimeter();
double area();
void showMessage();
private:
double a,b,c;
};
void Triangle::showMessage()
{
cout<<"三条边为:"<<a<<' '<<b<<' '<<c<<endl;
cout<<"三角形的周长为:"<<perimeter()<<'\t'<<"面积为:"<<area()<<endl;
}
double Triangle::perimeter()
{
return a+b+c;
}
double Triangle::area()
{
double x=(a*a+b*b-c*c)/(2*a*b);
return (a*b*sqrt(1-x*x))/2;
}
int main()
{
Triangle Tri1;
Tri1.showMessage();
Triangle Tri2(1.5);
Tri2.showMessage();
Triangle Tri3(1.5,1.5);
Tri3.showMessage();
Triangle Tri4(7,8,9);
Tri4.showMessage();
return 0;
}