Cylinder.cpp
上传用户:liubin
上传日期:2022-06-13
资源大小:85k
文件大小:1k
源码类别:

书籍源码

开发平台:

Visual C++

  1. //习题12.1中的cylinder.cpp文件
  2. //CYLINDER.CPP
  3. Cylinder::Cylinder(float a,float b,float r,float h)
  4.     :Circle(a,b,r),height(h){}
  5. void Cylinder::setHeight(float h){height=h;}
  6. float Cylinder::getHeight() const {return height;}
  7. float Cylinder::area() const
  8. { return 2*Circle::area()+2*3.14159*radius*height;}
  9. float Cylinder::volume() const
  10. {return Circle::area()*height;}
  11. ostream &operator<<(ostream &output,const Cylinder& cy)
  12. {output<<"Center=["<<cy.x<<","<<cy.y<<"], r="<<cy.radius<<", h="<<cy.height
  13.        <<"narea="<<cy.area()<<", volume="<<cy.volume()<<endl;
  14.  return output;
  15. }