/* * 程序的版权和版本声明部分 * Copyright (c)2013, 烟台大学计算机学院学生 .* All rightsreserved. * 作 者: 刘明亮 * 完成日期: 2013 年 5 月 12 日 * 版本号: v1.0 * 输入描述: * 问题描述: * 输出: */ #include<iostream> #include<iomanip> #include <Cstring> #define PI 3.1415 using namespace std; class Point { public: Point(double xx,double yy):x(xx),y(yy){}; friend ostream &operator<<(ostream&output,Point&); double x,y; }; ostream& operator<<(ostream&output,Point& e) { output<<"("<<e.x<<","<<e.y<<")"; return output; } class Circle:public Point { private: double r; public: Circle(double a,double b,double R):Point(a,b),r(R) {} double get_r() const {return r;} friend ostream &operator<<(ostream &output,const Circle &c); double area() const; }; double Circle::area() const { return r*r*PI; } ostream &operator<<(ostream &output,const Circle &c) { output<<"Center=["<<c.x<<", "<<c.y<<"], r="<<c.r<<", area="<<c.area()<<endl; return output; } class Cylinder:public Circle { private: double h; public: Cylinder(double a,double b,double R,double H):Circle(a,b,R),h(H){} friend ostream &operator<<(ostream &output,const Cylinder& cy); double volume() const; double Carea() const; }; ostream &operator<<(ostream &output,const Cylinder& cy) { output<<"Center=["<<cy.x<<","<<cy.y<<"], r="<<cy.get_r()<<", h="<<cy.h <<"\narea="<<cy.Carea( )<<", volume="<<cy.volume()<<endl; return output; } double Cylinder::volume() const { return area()*h; } double Cylinder::Carea() const { return 2*area()+(2*PI*get_r())*h; } int main() { Cylinder cy1(3.4,4.3,4.2,10); cout<<cy1<<endl; return 0; }