问题及代码:
/*
*文件名称:方柱类
*作者:隋文韬
*完成日期:2016.4.5
*问题描述:编写程序,求3个长方柱的体积,表面积。
*输入描述:长,宽,高
*程序输出:长方柱的体积,表面积
*/
#include<iostream>
#include<string>
using namespace std;
class Bulk
{
public:
void Input();//输入长宽高
void Output();//输出体积,表面积
void showMessage();//显示信息
private:
double length;
double width;
double heigth;
double volume;
double areas;
};
void Bulk::Input()
{
cout<<"请输入长宽高:";
cin>>length>>width>>heigth;
}
void Bulk::Output()
{
volume=length*width*heigth;
areas=2*(length*width*heigth);
}
void Bulk::showMessage()
{
cout<<"该长方柱的体积为:"<<volume<<endl;
cout<<"该长方柱的表面积为:"<<areas<<endl;
}
int main()
{
Bulk b1,b2,b3;
b1.Input();
b2.Input();
b3.Input();
b1.Output();
b2.Output();
b3.Output();
b1.showMessage();
b2.showMessage();
b3.showMessage();
return 0;
}