#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),height(z) {};
void get_value();
double area();
double valum();
void output();
private:
double length;
double width;
double height;
};
double Bulk::area()
{
double s;
s=length+width+height;
return s;
}
double Bulk::valum()
{
double v;
v=length*width*height;
return v;
}
void Bulk::get_value()
{
cin>>length>>width>>height;
}
void Bulk::output()
{
cout<<"面积:"<<area()<<endl;
cout<<"体积:"<<valum()<<endl;
}
int main()
{
int i=0;
Bulk b[5]={Bulk(2.3,4.5,6.7),Bulk(1.5,3.4),Bulk(10.5)};
b[4].get_value();
for(i=0; i<5; i++)
{
b[i].area();
b[i].valum();
b[i].output();
}
return 0;
}
对象操作长方柱类
最新推荐文章于 2016-06-02 17:14:51 发布