第三周 项目4-长方柱类

*/编写基于对象的程序求三个长方体的体积 表面积,数据成员包括长 宽 高,要求用成员函数
*/


*       
* 程序的版权和版本声明部分       
* Copyright (c)2013, 烟台大学计算机学院学生       
* All rightsreserved.       
* 文件名称: time.cpp                                  
* 作    者: 袁静                                   
* 完成日期:2013年3月15日       
* 版本号: v1.0             
* 输入描述:分别输入三个长方体的长  宽 高      
* 问题描述:     
*/  
#include <iostream>
using namespace std;
class Box
{
private:	
   float length;
   float width;
   float heigth;
public:
   void get_value();
   float volume();
    float areas();
    void displays();
};
void Box::get_value()
 {
     cout<<"请输入长 "<<" "<<"宽" <<""<<"高"<<""<<endl;
     cin>>length>>width>>heigth;
}

float Box::volume()
{	float e;
    e=length*width*heigth;
	return e;
    }
float Box::areas()
{
    float t;
   t=(length*width+length*heigth+width*heigth)*2;
   return t;

}
void Box::displays()
 {
     cout<<"该长方体的体积为"<<volume();
     cout<<"         表面积为"<<areas();
	 cout<<endl;
	 

 }
int main()

{
    Box b1,b2,b3;
    b1.get_value();
    b1.volume();
    b1.areas();
    b1.displays();
	
    b2.get_value();
    b2.volume();
    b2.areas();
    b2.displays();
	
    b3.get_value();
    b3.volume();
    b3.areas();
    b3.displays();
    return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章