#include
using namespace std;
#define PI 3.14159
class Cylinder{
public:
Cylinder(double radius,double height):radius(radius),height(height),volume(PI*radius*radius*height){
total_vol += volume;
}
double vol()const;
friend void getParas(double& radius,double&height,double&vol,double& total_vol,const Cylinder& obj);
private:
double radius; //radius
double height; //height
double volume;//volume of current object
static double total_vol;//total volume
};
double Cylinder::total_vol = 0;
double Cylinder::vol()const{
return this->volume;
}
void getParas(double& radius,double& height,double& vol,double& total_vol,const Cylinder& obj){ //get private member of Cylinder
radius = obj.radius;
height = obj.height;
vol = obj.volume;
total_vol = obj.total_vol;
}
int main(){
double rd = 0,hg = 0,vol = 0,total_vol = 0;
Cylinder cld_1(2,3.5),cld_2(5.2,7),cld_3(3.9,4.0);//3 objects
getParas(rd,hg,vol,total_vol,cld_3);
cout