⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 77.cpp

📁 c++课程习题集的源代码
💻 CPP
字号:
#include<iostream.h>
 const double PI=3.14;
 class point
{
 public :
  point(int x=0,int y=0);
  point(point& p);
  ~point();
  void display();
 protected:
  int x;
  int y;
};
 class circle:public point
{
 public:
  circle(float r,int x=0,int y=0);
  circle(circle& c);
  ~circle();
  void display(void);
  float get_area(void);
 protected:
  float *r;
};
 class cyl:public circle
{
 public:
  cyl(float a,float b,int d=0,int e=0);
  ~cyl();
  void display(void);
  double get_vol(void);
 private:
  float h;
};
 point::point(int x,int y)
{
 this->x=x;
 point::y=y;
 cout<<"点对象创建"<<endl;
}
 point::point(point &p)
{
 x=p.x;
 y=p.y;
 cout<<"点对象创建"<<endl;
}
 point::~point()
{
 cout<<"点对象消亡"<<endl;
}
 void point::display(void)
{
 cout<<"x="<<x<<",y="<<y<<endl;
}
 circle::circle(float r,int x,int y):point(x,y)
{
 this->r=new float;
 *this->r=r;
 cout<<"圆对象创建"<<endl;
}
 circle::circle(circle& c):point(c.x,c.y)
{
 r=new float;
 *r=*c.r;
 cout<<"圆对象创建"<<endl;
}
 circle::~circle()
{
 delete r;
 cout<<"圆对象消亡"<<endl;
}
 float circle::get_area(void)
{
 float v;
 v=PI**r**r;
 return(v);
}
 void circle::display(void)
{
 cout<<"圆心:"<<endl;
 point::display();
 cout<<"r="<<*r<<endl;
}
 cyl::cyl(float a,float b,int d,int e):circle(b,d,e)
{
 h=a;
 cout<<"圆柱体对象创建"<<endl;
}
 cyl::~cyl()
{
 cout<<"圆柱体对象消亡"<<endl;
}
void cyl::display(void)
{
 circle::display();
 cout<<"h="<<h<<endl;
}
 double cyl::get_vol(void)
{
 double v;
 v=get_area()*h;
 return(v);
}
 int main()
{
 cyl a(2,3,1,1);
 a.display();
 cout<<"圆柱体体积:"<<a.get_vol()<<endl; 
 return(0);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -