#include <iostream>
using namespace std;
class Bulk
{
public:
double area();
double volume();
void get_value();
void output();
Bulk(double l=1.0,double w=1.0,double h=1.0);
private:
double length,width,height;
};
Bulk::Bulk(double l,double w,double h)
{
length=l;
width=w;
height=h;
}
int main()
{
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
b[4].get_value();
//下面分别输出这5个长方柱的体积和表面积
b[0].output();
b[1].output();
b[2].output();
b[3].output();
b[4].output();
}
double Bulk::area()
{
return length*width*2+length*height*2+height*width*2;
}
double Bulk::volume()
{
return length*width*height;
}
void Bulk::get_value()
{
cin>>length>>width>>height;
}
void Bulk::output()
{
cout<<"个长方体的面积和体积分别为:";
cout<<area()<<" "<<volume()<<endl;
}
项目3-对象数组操作长方柱类
最新推荐文章于 2022-10-24 22:39:34 发布