c++实现长方体的面积和体积计算

c++实现长方体的面积和体积计算

一、知识体系:
(1)长方体的面积计算公式: s=2(a* b + b* c + c*a);
(2)长方体的体积计算公式:v=a* b* c;
二、算法实现

#include
using namespace std;

class cube
{
public:
    void getcube(double a , double b, double c)
    {
        m_a=a;
        m_b=b;
        m_c=c;
    }
    double geta()
    {
        return m_a;
    }
    double getb()
    {
        return m_b;
    }
    double getc()
    {
        return m_c;
    }

    double getm_s()
    {
        m_s = 2*(( m_a * m_b ) +(m_b * m_c )+(m_a * m_c ) );
        return m_s;
    }
    double getm_v()
    {
        m_v = m_a * m_b * m_c;
        return m_v;
    }
private:
    double m_a;//长
    double m_b;//宽
    double m_c;//高
    double m_s;//面积
    double m_v;//体积
};

int main()
{
    cube v1;
    v1.getcube(2, 3, 4);
    cout<< "长m_a:"<cout<< "宽m_b:"<cout<< "高m_c:"<cout<< "面积m_s:"<cout<< "体积m_v:"<return 0;
}

三、测试结果:
c++实现长方体的面积和体积计算_第1张图片

你可能感兴趣的:(c++实现长方体的面积和体积计算)