#include"iostream"
using namespace std;
class Bulk
{
public:
Bulk(double x=1.0,double y=1.0,double z=1.0):length(x),width(y),heigth(z) {}
void get_value();
void display();
private:
double length;
double width;
double heigth;
};
void Bulk::get_value()
{
cin>>length;
cin>>width;
cin>>heigth;
}
void Bulk::display()
{
cout<<" 长方柱的体积为: "<<length*width*heigth<<endl;
cout<<" 长方柱的表面积为: "<<2*(length*width+length*heigth+width*heigth)<<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();
for(int i=0;i<5;i++)
{
b[i].display();
}
return 0;
}
8.2对象数组操作长方柱类
最新推荐文章于 2020-10-23 21:04:35 发布