/*
* 程序的版權和版本聲明部分
* Copyright (c)2013, 煙臺大學計算機學院學生
* All rightsreserved.
* 文件名稱:score.cpp
* 作 者: 耿娜
* 完成日期: 2013 年 03 月 22 日
* 版本號: v1.0
* 輸入描述:長方體的高
* 問題描述:計算長方體的體積和表面積
* 輸出:計算長方體的體積和表面積
*/
#include<iostream>
using namespace std;
class Box
{public:
void get_value();
float area();
float volume();
void display();
float length;
float width;
float height;
};
void Box::get_value()
{
cout<<"請輸入長方柱的長,高,寬:";
cin>>length;
cin>>width;
cin>>height;
}
float Box::area()
{
return ((length*width+length*height+width*height)*2);
}
float Box::volume()
{
return (length*width*height);
}
void Box::display()
{
cout<<"volume of box is"<<volume()<<endl;
cout<<"area of box is"<<area()<<endl;
}
int main()
{
Box box1,box2,box3;
box1.get_value();
box1.display();
box2.get_value();
box2.display();
box3.get_value();
box3.display();
return 0;
}
第三週上機任務---長方柱類
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.