#include <iostream>
#include <cmath>
using namespace std;
class CSolid
{
public:
virtual double area()=0;
virtual double volume()=0;
};
class CCube:public CSolid
{
private:
double a;
public:
CCube(double l):a(l){};
double area(){return 6*a*a;};
double volume(){return a*a*a;};
};
class CBall:public CSolid
{
private:
double r;
public:
CBall(double a):r(a){};
double area(){return 4*3.14*r*r;};
double volume(){return 4/3*3.14*r*r*r;};
};
class CCylinder:public CSolid
{
private:
double r,h;
public:
CCylinder(double a,double b):r(a),h(b){};
double area(){return 6.28*r*r+6.28*r*h;};
double volume(){return 3.14*r*r*h;};
};
int main()
{
double s,v;
CCube c1(1);
CBall c2(2);
CCylinder c3(2,3);
CSolid *p;
p=&c1;
s=p->area();
v=p->volume();
cout<<"面积为:"<<s<<" 体积为:"<<v<<endl;
p=&c2;
s=p->area();
v=p->volume();
cout<<"面积为:"<<s<<" 体积为:"<<v<<endl;
p=&c3;
s=p->area();
v=p->volume();
cout<<"面积为:"<<s<<" 体积为:"<<v<<endl;
return 0;
}