2015年第十一周项目四:类组的设计(3)
2015-05-20 16:44
225 查看
#include <iostream> using namespace std; class Point { protected: double x; double y; public: Point(double,double); Point(){} ~Point(){} friend ostream & operator<<(ostream&,const Point &); }; ostream& operator<<(ostream&output,const Point &p) { output<<"("<<p.x<<","<<p.y<<")"; return output; } Point::Point(double m,double n) { x=m; y=n; } class Circle:public Point { protected: double r; public: double area(); Circle(double m,double n,double q):Point(m,n),r(q){} void setr(double q) { r=q; } friend ostream& operator <<(ostream&,const Circle&c); }; ostream& operator <<(ostream&output,const Circle&c) { output<<"("<<c.x<<","<<c.y<<","<<c.r<<")"; return output; } double Circle::area() { return 3.14*r*r; } class Cylinder:public Circle { private: double h; public: Cylinder(double m,double n,double q,double a):Circle(m,n,q),h(a){} double areas(); double volume(); ~Cylinder(){} friend ostream& operator<<(ostream& ,const Cylinder &); }; double Cylinder::areas() { return (2*area()+2*3.14*r*h); } double Cylinder::volume() { return (area()*h); } ostream& operator<<(ostream&output ,const Cylinder &c) { output<<"("<<c.x<<","<<c.y<<","<<c.r<<","<<c.h<<")"; return output; } int main() { Cylinder c(5,6,9,10); cout<<c<<endl; cout<<"the area of the cylinder:"; cout<<c.areas()<<endl; cout<<"the volume of the cylinder:"; cout<<c.volume(); return 0; }
相关文章推荐
- 2015年第十一周项目四:类族的设计
- 2015年第十一周项目四:类族的设计(2)
- 第十一周上机实践项目1(1):点-圆-圆柱类族的设计
- 第十周第十一周上机实践项目-项目1-(2)-点-圆-圆柱类族的设计
- 第十一周项目四类族的设计(3)
- 第十一周项目1.1—点 圆 圆柱类族的设计
- 第十一周项目一点圆圆柱类族的设计1
- 第十一周项目1-点-圆-圆柱类族的设计(2)
- 第十一周项目1.1—点 圆 圆柱类族的设计
- 第十一周【项目4 - 类族的设计】(2)
- 第十一周项目4-3:类族的设计:圆柱类->圆类->点类
- 第十一周项目1-点-圆-圆柱类族的设计(1)
- 第十一周 项目4-类族的设计(3)--补
- 第十一周项目一点圆圆柱类族的设计2
- 第十一周 项目4 类族的设计(1)
- 第十一周 项目四 类族的设计】
- 第十一周【项目1 - 点-圆-圆柱类族的设计3】
- 第十一周项目1.2— 点 圆 圆柱类族的设计
- 第十一周项目4 - 类族的设计
- 第十一周项目四类族的设计(1)