/*
*Copyright (c)2016,烟台大学计算机与控制工程学院
*All rights reserved.
*文件名称:main.cpp
*作 者:隋文韬
*完成日期:2016年5月19日
*版 本 号:v1.0
*
*问题描述:用对象数组操作长方柱类
*/
<pre class="cpp" name="code">#include<iostream>
#include<string>
using namespace std;
class Bulk
{
public:
Bulk(double l=1.0,double w=1.0,double h=1.0):length(l),width(w),heigth(h){}//默认参数的构造函数
void get_value();//输入长宽高
void output();//输出体积,表面积
private:
double length;
double width;
double heigth;
};
void Bulk::get_value()
{
cout<<"请输入长方柱的长宽高:"<<endl;
cin>>length>>width>>heigth;
}
void Bulk::output()
{
cout<<length*width*heigth<<" "<<2*(length*width*heigth)<<endl;
}
int main()
{
int i;
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
b[4].get_value();
//下面分别输出这5个长方柱的体积和面积
for(i=0;i<5;i++)
{
cout<<"第"<<i+1<<"个长方体体积,表面积分别为"<<endl;
b[i].output();
}
return 0;
}