#include<iostream>
using namespace std;
const double pi=3.14;
class Base{
protected:
double h;
public:
Base(double high)
{
h=high;
};
virtual double disp()=0;
};
class Cuboid:public Base{
protected:
double l;
double w;
public:
Cuboid(double high,double length,double width):Base(high)
{
l=length;w=width;
}
double disp()
{
return h*l*w;
}
};
class Cylinder:public Base{
protected:
double r;
public:
Cylinder(double high,double r1):Base(high)
{
r=r1;
}
double disp()
{
return pi*r*r*h;
}
};
int main()
{
Base *p;
Cuboid Cu(4.2,4.5,5.7);
Cylinder Cy(5.0,2.0);
p=&Cu;
cout<<"长方体的体积为:"<<p->disp()<<endl;
p=&Cy;
cout<<"圆柱体的体积为:"<<p->disp()<<endl;
system("pause");
return 0;
}