计算立方柱

来源:互联网 发布:mysql数据库用户权限 编辑:程序博客网 时间:2024/04/28 22:50
  1. /*  
  2. *Copyright (c) 2015,烟台大学计算机学院  
  3. *All rights reserved.  
  4. *文件名称:text.cpp  
  5. *作者:李德彪 
  6. *完成日期:2015年3月19日  
  7. *版本号:v1.0  
  8.  
  9. *问题描述:求立方柱的体积与表面积  
  10. *输入描述:输入九个数值,每三个分别表示长宽高 
  11. *程序输出:输出六个数值,每两个分别表示体积与表面积 
  12. */    
  13. #include<iostream>   
  14. using namespace std;  
  15. class Cube  
  16. {  
  17. public:  
  18.     void setRadius();  
  19.     float volume();  
  20.     float areas();  
  21.     double length,width,height;  
  22.   
  23. private:  
  24.     double radius;  
  25. };  
  26.   
  27. void Cube::setRadius()  
  28. {  
  29.     cout<<"请输入长方柱的长宽高:";  
  30.     cin>>length>>width>>height;  
  31. }  
  32.   
  33. float Cube::volume()  
  34. {  
  35.     return (length*width*height);  
  36. }  
  37.   
  38. float Cube::areas()  
  39. {  
  40.     return (length*width+length*height+height*width)*2;  
  41. }  
  42.   
  43. int main()  
  44. {  
  45.   
  46.     Cube c1,c2,c3;  
  47.     c1.setRadius();  
  48.     c1.volume();  
  49.     c1.areas();  
  50.     c2.setRadius();  
  51.     c2.volume();  
  52.     c2.areas();  
  53.     c3.setRadius();  
  54.     c3.volume();  
  55.     c3.areas();  
  56.     cout<<"c1长方柱的体积为:"<<c1.volume()<<"  "<<"c1长方柱的表面积为:"<<c1.areas()<<endl;  
  57.     cout<<"c2长方柱的体积为:"<<c2.volume()<<"  "<<"c2长方柱的表面积为:"<<c2.areas()<<endl;  
  58.     cout<<"c3长方柱的体积为:"<<c3.volume()<<"  "<<"c3长方柱的表面积为:"<<c3.areas()<<endl;  
  59.     return 0;  
  60. }  
0 0
原创粉丝点击