C++中点线圆的类定义及继承.doc

上传人:cn****1 文档编号:563579131 上传时间:2023-01-06 格式:DOC 页数:4 大小:32.51KB
返回 下载 相关 举报
C++中点线圆的类定义及继承.doc_第1页
第1页 / 共4页
C++中点线圆的类定义及继承.doc_第2页
第2页 / 共4页
C++中点线圆的类定义及继承.doc_第3页
第3页 / 共4页
C++中点线圆的类定义及继承.doc_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《C++中点线圆的类定义及继承.doc》由会员分享,可在线阅读,更多相关《C++中点线圆的类定义及继承.doc(4页珍藏版)》请在金锄头文库上搜索。

1、/*#include#includeusing namespace std;class Pointprivate: float x,y;public: Point() Point(float a,float b):x(a),y(b) Point(Point& a); float Distance(Point b);Point:Point(Point& a) x=a.x; y=a.y;float Point:Distance(Point b) return sqrt(x-b.x)*(x-b.x)+(y-b.y)*(y-b.y); class Line:public Pointprivate: P

2、oint a,b;public: Line(float x1,float y1,float x2,float y2):a(x1,y1),b(x2,y2) float Display();float Line:Display() return a.Distance(b);int main() Point a; Point b(7.8,9.8),c(34.5,67.8); a=c; cout两点之间距离是:a.Distance(b)endl; Line s(7.8,8.34,34.5,67.8); couts.Display()endl; return 0;*/#include using nam

3、espace std;#include class Point public: double x;double y;Point()Point(double xx,double yy)x = xx;y = yy;Point()double GetX()return x;double GetY()return y;virtual Show() coutthe point is (GetX(),GetY()endl;/圆由点派生class Circle : public Pointdouble Radius;public:Circle()Circle(double Rr)Radius = Rr;Ci

4、rcle()double GetCircleS()return (double)2*3.14*Radius;double GetRadius()return (double)Radius;/线由点派生class Line :public Pointpublic:Point Pa;Point Pb;Line()Line(Point pa,Point pb)Pa = pa;Pb = pb;double GetLineLengh()/获取直线长度double Lx = (Pb.GetX()-Pa.GetX()*(Pb.GetX()-Pa.GetX();double Ly = (Pb.GetY()-P

5、a.GetY()*(Pb.GetY()-Pa.GetY();return sqrt(Lx+Ly);virtual Show()coutthe length between Pa and Pb is GetLineLengh()endl;/矩形由线派生class Rect:public LinePoint Pc; Point Pd;public:double Lx2;double Ly2;Rect()Rect(Point pc,Point pd)Pc = pc;Pd = pd;double GetLineLengh2(); double GetRectS();double Rect:GetLin

6、eLengh2()double Lx2 = (abs(Pa.GetX()-Pc.GetX()*(abs(Pa.GetX()-Pc.GetX();double Ly2 = (abs(Pa.GetY()-Pc.GetY()*(abs(Pa.GetY()-Pc.GetY();return sqrt(double)(Lx2+Ly2);double Rect:GetRectS()return Lx2*Ly2;void main() Point Pa; Point Pb;Line ab(Pa,Pb);coutplease enter point Pa Pa.x ;cinPa.y ;Pa.Show();co

7、utplease enter point Pb Pb.x ;cinPb.y ;Pb.Show();ab.Show();/*void main() Point Pa(1,2);Point Pb(2,3);Point Pc(1,1);Point Pd(3,1);Line obj1(Pa,Pb);Rect obj2(Pa,Pc);Circle cir(2);cout直线1长度为:obj1.GetLineLengh()endl; cout直线2长度为:obj2.GetLineLengh2()endl; cout矩形面积为:obj2.GetRectS()endl;cout圆半径为cir.GetRadius()t圆面积为:cir.GetCircleS()endl;system(pause); */

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号