[cpp]
/*
* Copyright (c) 2013, 煙台大學計算機學院
* All rights reserved.
* 文件名稱:test.cpp
* 作者:樊露露
* 完成日期:2013 年 3 月 18 日
* 版本號:v1.0
*
* 輸入描述:無
* 問題描述:
* 程序輸出:
* 問題分析:
* 算法設計:略
*/
#include<iostream>
using namespace std;
class Block{
public:
void set_date();
void volume();//體積
void areas();//表面積
private:
float length;
float width;
float heigth;
};
void Block::set_date(){
cout<<"請依次輸入長方體的長、寬、高:";
cin>>length>>width>>heigth;
}
void Block::volume(){
float V;
V=length*width*heigth;
cout<<"此長方體的體積為 "<<V<<"。"<<endl;
}
void Block::areas(){
float S;
S=2*(length*width+width*heigth+length*heigth);
cout<<"此長方體的表面積為 "<<S<<"。"<<endl;
}
int main(){
Block block;
cout<<"第一個長方體"<<endl;
block.set_date();
block.volume();
block.areas();
cout<<"第二個長方體"<<endl;
block.set_date();
block.volume();
block.areas();
cout<<"第三個長方體"<<endl;
block.set_date();
block.volume();
block.areas();
return 0;
}