第2周项目2长方柱类计算3个长方柱的体积及表面积

/*日期:2014年3月14日;

*作者:范星月

*问题描述:计算长方柱的表面积及体积

*问题输入:输入长宽高

*问题输出:输出结果

*/

#include <iostream>

using namespace std;
class Bulk
{
    public:
    void  get_value();
    void  display();
private:
    float length;
    float width;
    float heigth;
    float volume;
    float  areas;
    void get_volume();
    void get_areas();

};
void Bulk::get_value()
{
    cin>>length>>width>>heigth;
    get_volume();
    get_areas();
}
void  Bulk::get_volume()
{
    volume= length*width*heigth;
}
void Bulk::get_areas()
{
    areas= 2*length*width+2*length*heigth+2*width*heigth;
}
void Bulk::display()
{
    cout<<"volume:"<<volume<<endl;
    cout<<"areas:"<<areas;
}

int main()
{
    Bulk b1,b2,b3;
    b1.get_value();
    cout<<"for b1:"<<endl;
    b1.display();
    b2.get_value();
    cout<<"for b2:"<<endl;
    b2.display();
    b3.get_value();
    cout<<"for b3:"<<endl;
    b3.display();
    return 0;


}



 

学习总结:

定义Bulk类,四个成员函数(两个共有,两个私有),五个数据成员,数据成员可以在成员函数中调用,但不可以在main函数中调用,直接在main函数中调用public成员函数,可以实现输入与输出,public成员函数是联系内外的接口

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值