第十周作业 3
来源:互联网 发布:淘宝商标侵权被告 编辑:程序博客网 时间:2024/06/06 07:44
#include <iostream> using namespace std; class Point { protected: double x,y;//分别代表横坐标和纵坐标 public: Point(double m=0,double n=0); void setpoint(double d,double e){x=d;y=e;} friend ostream& operator << (ostream& output,Point&c); double getx(){return x;} double gety(){return y;} }; Point::Point(double m,double n) { x=m; y=n; } ostream& operator << (ostream& output,Point&c) { output<<"点为:"<<"("<<c.x<<","<<c.y<<")"<<endl; return output; } class Circle:public Point { public: Circle(double c1,double c2,double c3):Point(c1,c2){r=c3;} friend ostream& operator << (ostream& output,Circle&c); void setR(double); double area( ); double getR(){return r;} protected: double r;//圆的半径 }; void Circle::setR(double m) { r=m; } double Circle::area() { return 3.1415926*r*r; } ostream& operator << (ostream& output,Circle&c) { output<<"圆心:"<<"("<<c.x<<","<<c.y<<")"<<"面积为:"<<c.area()<<endl; return output; } class Cylinder:public Circle { private: double h;//圆柱的高 public: Cylinder(double t1,double t2,double t3,double t4):Circle(t1,t2,t3){h=t4;} friend ostream& operator << (ostream& output,Cylinder&c); double area( ) ; double volume(); void setHeight(double m){h=m;} double getHeight(){return h;} }; double Cylinder::area( ) { return 2*Circle::area( )+2*3.14159*r*h; } double Cylinder::volume() { return area()*h; } ostream& operator << (ostream& output,Cylinder&c) { output<<"Center=["<<c.x<<","<<c.y<<"], r="<<c.r<<", h="<<c.h <<"\narea="<<c.area( )<<", volume="<<c.volume( )<<endl; return output; } int main( ) { Point t(5,6); cout<<t; Circle t1(7,3,1); cout<<t1; Cylinder cy1(3.5,2.4,5.2,10); cout<<"\noriginal cylinder:\nx="<<cy1.getx( )<<", y="<<cy1.gety( )<<", r=" <<cy1.getR( )<<", h="<<cy1.getHeight( )<<"\narea="<<cy1.area() <<",volume="<<cy1.volume()<<endl; cy1.setHeight(5); cy1.setR(7.5); cy1.setpoint(5,4); cout<<"\nnew cylinder:\n"<<cy1; system("pause"); return 0; }
感言:有点小难度 感觉派生不是很了解!!
- 第十周作业3
- 第十周作业 3
- 第十周作业
- 第十周作业 1
- 第十周作业
- 第十周作业
- 第十周作业一
- 第十周作业 1
- 第十周作业一
- 第十周作业2
- 第十周作业 1
- 第十周作业 2
- 第十周作业1
- 第十周作业
- 第十周作业
- 第十周作业
- [leetcode]第十周作业
- 第十周java作业
- 浅析android下如何通过jni监控wifi网络连接、dhcpcd执行和power电源控制
- Oracle 10.2.0.4的一个BUG--dbspicao10
- 开博
- 启动Tomcat时,抛异常原因之一
- lucene索引的建立昨天的问题已解决
- 第十周作业 3
- hdu 1248 寒冰王座(很水的完全背包)
- 第十周任务三
- php删除字符串中的所有空格
- Extjs 之 functions
- JAVA 正则表达式 (超详细)
- 位操作:一个整数的二进制表示中 有多少个1?
- 3ds Max 2011\2012下载及安装方法
- js的nextSibling属性