长方柱类

#include <iostream>    
using namespace std;    
class Box    
{    
public:    
    void get_value();    
   void get_display();    
private:    
    void get_volume();      
    void get_surface();    
    float width;        float height;    
    float volume;  
    float surface;  
};    
  
void Box::get_value()    
{     
    cout<<"请输入长,宽,高:";    
    cin>>lengh;    
   cin>>width;    
    cin>>height;    
    get_volume();      
    get_surface();    
}    
  
void Box::get_volume()    
{    
    volume=lengh*width*height;    
}    
  
void Box::get_surface()    
{    
    surface=2*(lengh*width+lengh*height+width*height);    
}    
  
void Box::get_display()    
{     
      
    cout<<"The volume is: "<<volume<<endl;    
    cout<<"The surface  is: "<<surface<<endl;    
}    
  
int main()    
{    
    Box b1,b2,b3;    
      
    b1.get_value();    
    cout<<"For box1: "<<endl;    
    b1.get_display();    
     
   b2.get_value();    
    cout<<"For box2: "<<endl;    
    b2.get_display();    
      
    b3.get_value();    
    cout<<"For box3: "<<endl;    
    b3.get_display();    
    return 0;    
}    

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值