#include<iostream.h>
#include<conio.h>
#include<math.h>
class Diem
{
  private:
    int x,y;
  public:
    Diem();
    Diem(int,int);
    Diem(const Diem&);
    ~Diem();
    Diem& operator=(const Diem &);
    friend ostream& operator<<(ostream& os, Diem&);
    friend istream& operator>>(istream& is, Diem&);
    void SetX(int);
    void SetY(int);
    int PutX();
    int PutY();
    Diem doi(int,int);
    void in();
    void nhap();
};
Diem::Diem()
{
    x=y=0;
}
Diem::Diem(int x1,int y1)
{
    x=x1; y=y1;
}
Diem::Diem(const Diem & d)
{
    x=d.x; y=d.y;
}
Diem::~Diem(){}
Diem&Diem:: operator=(const Diem& d)
{
    x=d.x; y=d.y;
    return *this;
}
ostream& operator<<(ostream& os, Diem& d)
{
    os<<“(“<<d.x<<“,”<<d.y<<“)”;
    return os;
}
istream& operator>>(istream& is, Diem& d)
{
    cout<<“\n Nhap Hoanh do: “;
    is>>d.x;
    cout<<“\n Nhap Tung do: “;
    is>>d.y;
    return is;
}
void Diem::SetX(int x1)
{
    x=x1;
}
void Diem::SetY(int y1)
{
    y=y1;
}
int Diem::PutX()
{
    return x;
}
int Diem::PutY()
{
    return y;
}
Diem Diem::doi(int dx, int dy)
{
    return Diem(x+dx, y+dy);
}
void Diem::nhap()
{
    cout<<“\n Nhap Hoanh do: “;
    cin>>x;
    cout<<“\n Nhap Tung do: “;
    cin>>y;
}
void Diem::in()
{
    cout<<“(“<<x<<“,”<<y<<“)”;
}
//Diem Mau
class Dthang
{
  private:
    Diem A,B;
  public:
    Dthang();
    Dthang(Diem,Diem);
    Dthang(int,int,int,int);
    Dthang(const Dthang&);
    ~Dthang();
    Dthang& operator=(const Dthang&);
    friend ostream& operator<<(ostream& os, Dthang&);
    friend istream& operator>>(istream& is, Dthang&);
    float ddai();
    Dthang TTien(int,int);
    void nhap();
    void in();
};
Dthang::Dthang():A(),B()
{
    A.SetX(0);A.SetY(0);
    B.SetY(0);B.SetY(0);
}
Dthang::Dthang(Diem A1, Diem B1):A(A1),B(B1)
{
    A=A1; B=B1;
}
Dthang::Dthang(int x1, int y1, int x2, int y2):A(x1,y1),B(x2,y2)
{
    A.SetX(x1); A.SetX(y1);
    B.SetX(x2); B.SetX(y2);
}
Dthang::Dthang(const Dthang& d):A(d.A),B(d.B)
{
   A=d.A; B=d.B;
}
Dthang::~Dthang(){}
Dthang& Dthang::operator=(const Dthang& d)
{
     A=d.A; B=d.B;
     return *this;
}
ostream& operator<<(ostream& os, Dthang& d)
{
    os<<“|”<<d.A<<” “<<d.B<<“|”;
    return os;
}
istream& operator>>(istream& is, Dthang& d)
{
    cout<<“\n Nhap diem dau: “;
    is>>d.A;
    cout<<“\n Nhap diem cuoi: “;
    is>>d.B;
    return is;
}
float Dthang::ddai()
{
    float d;
    d=1.0*sqrt(pow(A.PutX()-B.PutX(),2)+pow(A.PutY()-B.PutY(),2));
    return d;
}
Dthang Dthang::TTien(int dx, int dy)
{
    return Dthang(A.doi(dx,dy),B.doi(dx,dy));
}
void Dthang::nhap()
{
    cout<<“\n Nhap diem dau: “;
    cin>>A;
    cout<<“\n Nhap diem cuoi: “;
    cin>>B;
}
void Dthang::in()
{
    cout<<“|”<<A<<” “<<B<<“|”;
}
int main()
{
    Diem A(2,5); Diem B(20,35);
//    cout<<“\n Doan thang AB: “<<Dthang(A,B);
    Dthang CD;
    CD.nhap();
    cout<<“\n Doan Thang CD: “<<CD;
    cout<<“\n Doi dai Doan CD: “<<CD.ddai();
//    cout<<“\n Doan Thang CD sau khi tinh tien doan (5,3): “<<CD.TTien(5,3);
    getch();
}