#include
using namespace std;
#define PI 3.14
class graphics
{
protected:
double s,v;
public:
virtual void print()=0;
virtual void calc()=0;
};
class ball:public graphics
{
private:
double r;
public:
ball()
{
r=0;
}
ball(double r1)
{
r=r1;
}
void calc()
{
s=4*PI*r*r;
v=(4*PI*r*r*r)/3;
}
void print()
{
cout<<"球面积:"< }
~ball()
{
cout<<"感谢您的使用!"< }
};
class cuboid:public graphics
{
private:
double x,y,z;
public:
cuboid()
{
x=0;
y=0;
z=0;
}
cuboid(double x1,double y1,double z1)
{
x=x1;
y=y1;
z=z1;
}
void calc()
{
s=(x*y+y*z+x*z)*2;
v=x*y*z;
}
void print()
{
cout<<"长方体面积:"< }
~cuboid()
{
cout<<"感谢您的使用!"< }
};
class column:public graphics
{
private:
double r,h;
public:
column()
{
r = 0;
h = 0;
}
column(double r1,double h1)
{
r = r1;
h = h1;
}
void calc()
{
s = 2*PI*r*r+2*PI*r*h;
v = PI*r*r*h;
}
void print()
{
cout<<"圆柱面积:"< }
~column()
{
cout<<"感谢您的使用!"< }
};
int main()
{
graphics *p;
while(1)
{
string i;
cout<<"选择操作(球:1,长方体:2,圆柱体:3,退出:4)"<
cin>>i;
cout<<"'\33[2J\33[1;2H"<
if(i=="1")
{
double r;
cout<<"请输入球半径:"< cin>>r;
ball b(r);
p = &b;
p->calc();
p->print();
}
else if(i=="2")
{
double x,y,z;
cout<<"请输入长方体长:"< cin>>x;
cout<<"请输入长方体宽:"< cin>>y;
cout<<"请输入长方体高:"< cin>>z;
cuboid b(x,y,z);
p = &b;
p->calc();
p->print();
}
else if(i=="3")
{
double h,r;
cout<<"请输入圆柱半径:"< cin>>r;
cout<<"请输入圆柱高:"< cin>>h;
column b(r,h);
p = &b;
p->calc();
p->print();
}
else if(i=="4")
{
cout<<"退出程序!"< break;
}
else
cout<<"没有此选项,重新选择!"< }
return 0;
}
阅读(901) | 评论(0) | 转发(0) |