慕勒3428872
#include <iostream>#define PI 3.14using namespace std;class container{public:container(int radius=0){}virtual void Square()=0;virtual void Volume()=0;//private: //因为这个是私有的,不能被继承类访问,为了简单,我将它改成了publicint radius;};class cube:public container{public:cube(int radius1):container(radius1){} //这里int必须去掉virtual void Square(){square1=4*PI*radius*radius; //////////////////基类的成员是radius,没有1,你写成了radius1cout<<"the cube's square is:"<<square1<<endl;}virtual void Volume(){volume1=4/3*PI*radius*radius*radius; //////////////////基类的成员是radius,没有1,你写成了radius1cout<<"the cube's volume is:"<<square1<<endl;}private:double square1,volume1;};class sphere:public container{public:sphere(int radius1):container(radius1){} //这里int必须去掉virtual void Square(){square2=6*radius*radius; //////////////////基类的成员是radius,没有1,你写成了radius1cout<<"the sphere's square is:"<<square2<<endl;}virtual void Volume(){volume2=radius*radius*radius; //////////////////基类的成员是radius,没有1,你写成了radius1cout<<"the sphere's volume is:"<<volume2<<endl;}private:double square2,volume2;};class cylinder:public container{public:cylinder(int radius1):container(radius1){} //这里int必须去掉virtual void Square(){cout<<"please input the cylinder's height=";cin>>height;square3=2*PI*radius*radius+2*PI*radius*height; //////////////////基类的成员是radius,没有1,你写成了radius1cout<<"the cylinder's square is:"<<square3<<endl;}virtual void Volume(){volume3=PI*radius*radius*height; //////////////////基类的成员是radius,没有1,你写成了radius1cout<<"the cylinder's volume is:"<<volume3<<endl;}private:double square3,volume3;int height;};int main(){//container container1;int a;cout<<"Please input a radius=";cin>>a;cube cube1(a);sphere sphere1(a);cylinder cylinder1(a);cube1.Volume();cube1.Square();sphere1.Volume();sphere1.Square();cylinder1.Square();cylinder1.Volume();return 0;}