c++第五次作业

  1. /*  
  2. * 文件名称:Ex5-6.cpp  
  3. * 作    者:徐浩宁  
  4. * 完成日期:2017 年 4 月 24 日  
  5. * 版 本 号:v1.0  
  6. * 对任务及求解方法的描述部分: 下面设计一个三角形类,请给出各成员函数的定义
  7. * 输入描述:  
  8. * 问题描述:
  9. * 程序输出:
  10. * 问题分析:
  11. * 算法设计:
  12.  class Triangle  
    {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; 


    #include <iostream>  
    #include <Cmath>  
    #include "Triangle.h"  
    using namespace std;  
    void main(void)  
    {   Triangle  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;  
        system ("PAUSE");  
    }  


    #include <iostream>  
    #include <Cmath>  
    #include "Triangle.h"  
    using namespace std;  
    void Triangle::Setabc(float x, float y, float z)  
    {  
     cout << "请输入三角形三边值:" << endl;  
       
            cout << "数据违法!请重新输入: "; 
      else 
       break; 
     }*/  
     a = x;  
     b = y;  
     c = z;  
    }  
    void Triangle::Getabc(float *x, float *y, float *z)  
    {  
     *x = a;  
     *y = b;  
     *z = c;  
    }  
    float Triangle::Perimeter(void)  
    {  
     int l;  
     l = a + b + c;  
     return (l);  
    }  
    float Triangle::Area(void)  
    {  
     double s,m;  
     m = (a + b + c) / 2;  
      
     s = sqrt((m - a) * (m - b) * (m - c));  
     return (s);  
    }  
  13. 二.运算结果

  14.  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值