0
点赞
收藏
分享

微信扫一扫

定义三角形类,完成:为三边置值、取三边的值并输出、求三角形周长、求三角形面积、输出三角形周长和面积。

年夜雪 2022-03-11 阅读 163
c++

#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.

举报

相关推荐

0 条评论