#include <iostream>
#include <cmath>
using namespace std;
struct A
{
double x,y,z;
double l,s;
public:
void l1()
{
l=x+y+z;
cout<<l<<endl;
}
void s1()
{
double i=l/2;
s=sqrt(i*(i-x)*(i-y)*(i-z));
cout<<s<<endl;
}
};
int main()
{
struct A a;
cout<<"输入三角形的三条边:";
cin>>a.x>>a.y>>a.z;
cout<<"三条边的长度分别为:";
cout<<a.x<<" "<<a.y<<" "<<a.z<<endl;
cout<<"三角形的周长:";
a.l1();
cout<<"三角形的面积:";
a.s1();
return 0;
}
运行结果:
输入三角形的三条边:3 4 5
三条边的长度分别为:3 4 5
三角形的周长:12
三角形的面积:6
Process returned 0 (0x0) execution time : 4.578 s
Press any key to continue.