第五周作业(三)

  1. #include <iostream>  
  2. using namespace std;  
  3. class Box  
  4. {  
  5. public:  
  6.  Box();  
  7.  Box(int h,int w,int l):height(h),width(w),length(l){};  
  8.  int volume();  
  9.  int area();  
  10.  void input();  
  11. private:  
  12.  int height;  
  13.  int width;  
  14.  int length;  
  15. };  
  16.   
  17. int Box:: volume()  
  18. {  
  19.  return(height*width*length);  
  20. }  
  21. int Box::area()  
  22. {  
  23.  int s;  
  24.  s=height*width+width*length+height*length;  
  25.  return (2*s);  
  26. }  
  27. Box::Box()  
  28. {  
  29.  height=10;  
  30.  width=10;  
  31.  length=10;  
  32. }  
  33. void Box::input()  
  34. {  
  35.  cin>>height>>width>>length;  
  36. }  
  37. int main()  
  38. {  
  39.  Box a[5]={  
  40.   Box(10,12,15),  
  41.   Box(15,18,20),  
  42.   Box(16,20,26),  
  43.   Box(),  
  44.   Box()  
  45.  };  
  46.     cout<<"长方柱1的面积是:"<<a[0].area()<<'\t'<<"体积是:"<<a[0].volume()<<endl<<endl;  
  47.     cout<<"长方柱2的面积是:"<<a[1].area()<<'\t'<<"体积是:"<<a[1].volume()<<endl<<endl;  
  48.     cout<<"长方柱3的面积是:"<<a[2].area()<<'\t'<<"体积是:"<<a[2].volume()<<endl<<endl;  
  49.     cout<<"长方柱4的面积是:"<<a[3].area()<<'\t'<<"体积是:"<<a[3].volume()<<endl<<endl;  
  50.     cout<<"请输入长方柱5的长,宽,高:";  
  51.     a[4].input();  
  52.     cout<<endl;  
  53.     cout<<"长方柱5的面积是:"<<a[4].area()<<'\t'<<"体积是:"<<a[4].volume()<<endl<<endl;  
  54.     return 0;  
  55. }  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值