#include <iostream>
using namespace std;
class Bulk
{
public:
Bulk(double le=1.0,double we=1.0,double he=1.0):legth(le),wedth(we),heigh(he){};
double volume();
double surfacearea();
void display();
void get_vaule();
private:
double legth;
double wedth;
double heigh;
};
double Bulk::volume()
{
return legth*wedth*heigh;
}
double Bulk::surfacearea()
{
return (legth*wedth+legth*heigh+wedth*heigh)*2;
}
void Bulk::get_vaule()
{
cout<<"请输入长宽高:";
cin>>legth>>wedth>>heigh;
}
void Bulk::display()
{
cout<<"体积是:"<<volume()<<"面积是: "<<surfacearea()<<endl;
}
int main()
{
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
b[4].get_vaule();
for(int i=0;i<5;i++)
{
cout<<"第"<<i+1<<"个"<<"长方体"<<endl;
b[i].display();
}
return 0;
}
运行结果: