#include <iostream>
using namespace std;
class Bulk
{
private:
double length;
double width;
double heigth;
public:
Bulk(double x=1.0,double y=1.0,double z=1.0):length(x),width(y),heigth(z){};
void get_value();
void output();
};
void Bulk::get_value()
{
cin>>length>>width>>heigth;
}
void Bulk::output()
{
cout<<"长方柱的体积为:"<<length*width*heigth;
cout<<"长方柱的面积为:"<<(length*width+length*heigth+width*heigth)/2<<endl;
}
int main()
{
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
b[4].get_value();
int i=0;
for(i=0;i<5;i++)
{
b[i].output();
}
return 0;
}
2015年第四周项目三:用对象数组操作长方柱类
最新推荐文章于 2015-04-12 11:46:11 发布