/*
*Copyright(c)2016.烟台大学计算机学院
*All right reserved.
*文件名称:test.cpp
*作者:黄金婵.
*完成日期:2016年6月14号
*版本号:v1.0
*
*问题描述:定义点类Point,并以点类为基类,派生出直线类Line,从基类中继承的点的信息表示直线的中点。请阅读下面的代码,并将缺少的部分写出来
*程序输入:
*输出描述:
*/
#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;
}