第十一周上机项目4点类派生直线类
2015-05-20 08:47
363 查看
/* *Copyright (c) 2015, 烟台大学计算机学院 *All rights reserved. *文件名称:text.cpp *作者:陈栋梁 *完成日期:2015年 5月 20日 *版本号:v1.0 * */ #include<iostream> #include<Cmath> using namespace std; class Point { public: Point():x(0),y(0) {}; Point(double x0, double y0):x(x0), y(y0) {}; double getX() { return x; } double getY() { return y; } void PrintPoint(); protected: double x,y; }; void Point::PrintPoint() { cout<<"Point:("<<x<<","<<y<<")"; } class Line: public Point { public: Line(Point pts, Point pte); double Length(); void PrintLine(); private: class Point pts,pte; }; Line::Line(Point pt1, Point pt2):Point((pt1.getX()+pt2.getX())/2,(pt1.getY()+pt2.getY())/2) { pts=pt1; pte=pt2; } double Line::Length() { double dx = pts.getX() - pte.getX(); double dy =pts.getY() - pte.getY(); return sqrt(dx*dx+dy*dy); } void Line::PrintLine() { cout<<" 1st "<<endl; pts.PrintPoint(); cout<<" 2nd "<<endl; pte.PrintPoint(); cout<<" The Length of Line: "<<Length()<<endl; } int main() { Point ps(-2,5),pe(7,9); Line l(ps,pe); cout<<"About the Line: "<<endl; l.PrintLine(); cout<<"The middle point of Line is: "; l.PrintPoint(); return 0; }
运行结果:
相关文章推荐
- 第十一周上机实践项目——点类派生直线类
- 第十一周上机实践项目3——点类派生直线类
- 第十一周上机项目三点类派生直线类
- 第十一周项目三 点类派生直线类
- 第十一周项目3——点类派生直线类
- 第十一周项目3点类派生直线类
- 第十一周项目二——点类派生直线类
- 第十一周(项目三)——点类派生直线类 。
- 第十一周项目三-点类派生直线类
- 第十一周项目点类派生直线类
- 第十一周 项目3-点类派生直线类
- 第十一周项目3:点类派生直线类
- 第十一周项目3-点类派生直线类
- 第十一周 项目3 - 点类派生直线类】定义点类Point,并以点类为基类,继承关系
- 第十一周 项目 3 点类派生直线类 .
- 第十一周项目3-点类派生直线类
- 第十一周 项目3 - 点类派生直线类
- 第十一周 项目三:点类派生直线类
- 第十一周项目三点类派生直线类
- 第十一周【项目3 - 点类派生直线类】