第十周实验报告3.0

来源:互联网 发布:云服务器开放端口 编辑:程序博客网 时间:2024/05/28 04:53

/* (程序头部注释开始)   
* 程序的版权和版本声明部分   
* Copyright (c) 2011, 烟台大学计算机学院学生    
* All rights reserved.   
* 文件名称:renxiaoning3                          
* 作    者:任小宁                          
* 完成日期:  2012   年   4   月    23日   
* 版 本 号:201158504431          
* 对任务及求解方法的描述部分   
* 输入描述:

#include <iostream>#include<Cmath>     #include<iomanip>     using namespace std;const double PI = 3.141592653;class Point//点类声明{public:Point(){x = 0;y = 0;}Point(double x0,double y0):x(x0),y(y0){ }~Point(){ }    double getx(){return x;}      double gety(){return y;}      friend ostream &operator << (ostream & input, Point & c);  protected:      double x, y;   //点的横坐标和纵坐标   };ostream &operator << (ostream & input, Point & c){input << "点:(" << c.x << "," << c.y << ")";        return input;  }class Circle: public Point   //以点类为基类的派生类{  public:      Circle(){radius = 0;}      Circle(double x0, double y0, double r):Point(x0, y0),radius(r){ }      //构造函数       ~Circle(){}     double getr(){return radius;}  double area1();    friend ostream &operator << (ostream & out, Circle & c);  protected:      double radius;  };  double Circle::area1() //圆形面积{double c_area = PI * getr() * getr();return c_area;}ostream &operator << (ostream & out, Circle & c)  {      out << "(" << c.getx() << "," << c.gety() << ")" << "为圆心" << c.radius << "为半径的圆";        return out;  }    class Cylinder: public Circle  //以圆类为基类的派生类{  public:      Cylinder(){height = 0;}      Cylinder(double x1,double y1, double r1, double h):Circle(x1, y1, r1), height(h){ }      ~Cylinder(){}      double geth(){return height;}      double area2();      double volume();      friend ostream &operator << (ostream & out, Cylinder & c);  private:      double height;  };     double Cylinder::area2()  {        //double c_area = PI * getr() * getr();        double c_cir = 2 * PI * getr() * height;   //圆柱侧面积      return (c_cir + 2 * area1());  }    double Cylinder::volume()  {      return (PI * getr() * getr() * height);  }    ostream &operator << (ostream & out, Cylinder & c)  {      out << "(" << c.getx() << "," << c.gety() << ")" << "为圆心" << c.radius << "为半径" << c.height << "为高的圆柱体";        return out;  }    int main()  {      Cylinder cy(2, 2, 1, 3);        cout << cy << endl;        cout << setiosflags(ios::fixed) << setprecision(2);        cout << "表面积是:" << cy.area2() << endl;        cout << "体积是:" << cy.volume() << endl;        system("pause");        return 0;  } (2,2)为圆心1为半径3为高的圆柱体表面积是:25.13体积是:9.42请按任意键继续. . .