现在的位置: 首页 > 综合 > 正文

第五周作业(三)

2014年01月08日 ⁄ 综合 ⁄ 共 722字 ⁄ 字号 评论关闭

  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'<<
【上篇】
【下篇】

抱歉!评论已关闭.