第三週 項目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;
}

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