我只写了第一种方法,你先拿去交吧
#include
#include
using namespace std;
class Point
{
public:
Point(double x1=0, double y1=0){px = x1; py = y1;};
~Point(){};
void Display(void);
double Distance(Point &point);
double px, py;
};
double Point::Distance(Point &point)
{
double t1, t2;
t1 = point.px - this->px;
t2 = point.py - this->py;
return sqrt(t1*t1+t2*t2);
}
void Point::Display()
{
cout<<"x: "<
class Line:public Point
{
public:
Line(double x1, double y1, double x2, double y2);
Line (Line &line);
double Display(Line &line);
~Line();
double x, y;
};
Line::Line(double x1, double y1, double x2, double y2)
{
x = x2 - x1;
y = y2 - y1;
}
Line::Line(Line &line)
{
x = line.x;
y = line.y;
}
double Line::Display(Line &line)
{
return sqrt(x*x+y*y);
}
Line::~Line(){};
void main()
{
Point a;
Point b(7.8, 7.9), c(34.5, 67.8);
a = c;
cout<<"两点之间的距离为: "<
Line s1(s);
cout<