#include<iostream>
using namespace std;
class Point{
public:
void Display()
{
cout<<"点("<<x<<", "<<y<<")"<<endl;
}
int Distance(Point p)
{
return ((x-p.GetX())*(x-p.GetX()) + (y - p.GetY())*(y - p.GetY()));
}
Point(int xPos,int yPos)
{
x = xPos;
y = yPos;
}
int GetX()
{
return x;
}
int GetY()
{
return y;
}
~Point()
{
}
private:
int x;
int y;
};
class Line : public Point
{
public:
Line(Point p,int x,int y) : Point(x,y),p1(p)
{
}
~Line()
{
}
void SetColor(int c)
{
color = c;
}
int GetColor()
{
return color;
}
int Distance()
{
Point tmp(GetY(),GetY());
return p1.Distance(tmp);
}
void Display()
{
cout<<"线[("<<GetX()<<", "<<GetY()<<"),"<<
"("<<p1.GetX()<<", "<<p1.GetY()<<")] 颜色为"<<color<<endl;
}
private:
int color;
Point p1;
};
int main()
{
Point p0(1,5);
Point p1(0,0);
p0.Display();
p1.Display();
cout<<"p0和p1的距离是:"<<p0.Distance(p1)<<endl;;
Line l(p0,5,5);
l.Display();
cout<<"线段长度:"<<l.Distance()<<endl;
return 0;
}
using namespace std;
class Point{
public:
void Display()
{
cout<<"点("<<x<<", "<<y<<")"<<endl;
}
int Distance(Point p)
{
return ((x-p.GetX())*(x-p.GetX()) + (y - p.GetY())*(y - p.GetY()));
}
Point(int xPos,int yPos)
{
x = xPos;
y = yPos;
}
int GetX()
{
return x;
}
int GetY()
{
return y;
}
~Point()
{
}
private:
int x;
int y;
};
class Line : public Point
{
public:
Line(Point p,int x,int y) : Point(x,y),p1(p)
{
}
~Line()
{
}
void SetColor(int c)
{
color = c;
}
int GetColor()
{
return color;
}
int Distance()
{
Point tmp(GetY(),GetY());
return p1.Distance(tmp);
}
void Display()
{
cout<<"线[("<<GetX()<<", "<<GetY()<<"),"<<
"("<<p1.GetX()<<", "<<p1.GetY()<<")] 颜色为"<<color<<endl;
}
private:
int color;
Point p1;
};
int main()
{
Point p0(1,5);
Point p1(0,0);
p0.Display();
p1.Display();
cout<<"p0和p1的距离是:"<<p0.Distance(p1)<<endl;;
Line l(p0,5,5);
l.Display();
cout<<"线段长度:"<<l.Distance()<<endl;
return 0;
}