#include<iostream>
#include<cmath>
using namespace std;
class Point
{
public:
Point(int xx=0,int yy=0) { X=xx; Y=yy; }
Point(Point &p); //Line拷贝函数里有p(L.p1)语句,Point也需要拷贝函数
int GetX() { return X; } //X\Y为私有数据成员,用函数调用其值
int GetY() { return Y; }
private:
int X,Y;
};
Point::Point(Point &p)
{
X=p.X;
Y=p.Y;
}
class Line
{
public:
Line(Point xp1,Point xp2); //类的组合
Line(Line &L);
double getLen() { return len; }
private:
Point p1,p2;
double len;
};
Line::Line(Point xp1,Point xp2)
:p1(xp1),p2(xp2)
{
double x=double(p1.GetX()-p2.GetX());
double y=double(p1.GetY()-p2.GetY());
len=sqrt(x*x+y*y);
}
Line::Line(Line &L):p1(L.p1),p2(L.p2)
{
len=L.len;
}
#include<cmath>
using namespace std;
class Point
{
public:
Point(int xx=0,int yy=0) { X=xx; Y=yy; }
Point(Point &p); //Line拷贝函数里有p(L.p1)语句,Point也需要拷贝函数
int GetX() { return X; } //X\Y为私有数据成员,用函数调用其值
int GetY() { return Y; }
private:
int X,Y;
};
Point::Point(Point &p)
{
X=p.X;
Y=p.Y;
}
class Line
{
public:
Line(Point xp1,Point xp2); //类的组合
Line(Line &L);
double getLen() { return len; }
private:
Point p1,p2;
double len;
};
Line::Line(Point xp1,Point xp2)
:p1(xp1),p2(xp2)
{
double x=double(p1.GetX()-p2.GetX());
double y=double(p1.GetY()-p2.GetY());
len=sqrt(x*x+y*y);
}
Line::Line(Line &L):p1(L.p1),p2(L.p2)
{
len=L.len;
}