Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1498589
  • 博文数量: 329
  • 博客积分: 2773
  • 博客等级: 少校
  • 技术积分: 4219
  • 用 户 组: 普通用户
  • 注册时间: 2012-02-24 14:17
个人简介

淡定从容,宁静致远

文章分类

全部博文(329)

文章存档

2016年(4)

2015年(50)

2014年(68)

2013年(45)

2012年(162)

分类: C/C++

2012-12-16 23:37:07

#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;
}
阅读(857) | 评论(0) | 转发(0) |
0

上一篇:day5

下一篇:链表

给主人留下些什么吧!~~