第十周实验报告(三)
来源:互联网 发布:云服务器开放端口 编辑:程序博客网 时间:2024/06/06 01:04
#include<iostream> #include<Cmath> #define pi 3.1415926using namespace std;class Point //定义坐标点类 { public: double x,y; //点的横坐标和纵坐标 Point(){x=0;y=0;} Point(double x0,double y0) {x=x0; y=y0;} ~Point () { cout<<"析构函数执行完毕(Destructor function performs finished)"<<endl; } double get_x(){return x;} double get_y(){return y;} friend ostream &operator << (ostream & output, Point & c); }; class Circle: public Point //利用坐标点类定义圆类, 其基类的数据成员表示圆的中心 { private: double d; public: Circle(double xx,double yy,double dd): Point(xx,yy) ,d(dd){} //构造函数 ~Circle() { } friend ostream &operator << (ostream & output, Circle & c); double get_d(){return d;} }; class Cylinder: public Circle { private: double h; public: Cylinder(double xx,double yy,double dd,double hh): Circle (xx,yy,dd),h(hh){} //构造函数 ~Cylinder() { } friend ostream &operator << (ostream & output,Cylinder & c); double get_h(){return h;} double superficial_area(); //表面积 double volume(); //体积 };ostream &operator << (ostream & output, Point & c) { output<<"点的横坐标为:"<<c.x<<" "<<"点的纵坐标为:"<<c.y<<endl; return output; } ostream &operator << (ostream & output, Circle & c) { output<<"圆的半径为:"<<c.get_d()<<"圆的圆心为"<<"("<<c.get_x()<<","<<c.get_y()<<")"<<endl; return output; } ostream &operator << (ostream & output,Cylinder & c) { output<<"圆的高为:"<<c.get_h()<<"圆的半径为:"<<c.get_d()<<"圆的圆心为"<<"("<<c.get_x()<<","<<c.get_y()<<")"<<endl; return output; } double Cylinder::superficial_area() //表面积 { double s; s=2*pi*get_d()*get_d()+2*pi*get_d()*get_h(); return s; } double Cylinder::volume() //体积 { double v; v=pi*get_d()*get_d()*get_h(); return v; } int main() { Point p(1,1); cout<<p; Circle ci(1,2,6); cout<<ci; Cylinder cy(1,2,3,4); cout<<cy; cout<<"圆柱的体积为:"<<cy.volume ()<<endl; cout<<"圆柱的表面积为:"<<cy.superficial_area ()<<endl; system("pause"); return 0; }
运行结果:
点的横坐标为:1 点的纵坐标为:1
圆的半径为:6圆的圆心为(1,2)
圆的高为:4圆的半径为:3圆的圆心为(1,2)
圆柱的体积为:113.097
圆柱的表面积为:131.947
请按任意键继续. . .
- 第十周实验报告(三)
- 第十周实验报告(三)
- 第十周实验报告(三.1)
- 第十周C++实验报告(三)
- 第十周实验报告三
- 第十周实验报告三
- 第十周实验报告(任务三)【派生类2】
- 第十周实验报告 任务三(改)
- 第十周实验报告 任务三
- 第十一周实验报告(三)
- 第十周实验报告
- 第十周实验报告
- 第十周实验报告(五)
- 第十周实验报告(五)
- 第十周实验报告(一)
- 第十周实验报告(二)
- 第十周实验报告(1)
- 第十周实验报告(2)
- 第十周实验报告(二)
- Java中HashMap和HashSet的使用练习
- 第十周 任务一
- php安装oracle扩展问题
- 最简单的Dialog
- 第十周实验报告(三)
- oracle查询
- 第十周实验报告2.0
- 第十周实验报告(3)
- JavaScript用户自定义函数
- 查看oracle当前连接数
- C++多态
- sql查询指定列超过一定条数的记录
- SQLServer的临时表