#include <iostream>
#include <fstream>
using namespace std;
class Point {
public:
Point (const int x, const int y) {Point::x = x; Point::y = y;}
Point () {Point::x = 0; Point::y = 0;}
// Point operator + (const Point &p) {return Point(x + p.x,y + p.y);}
friend Point operator + (const Point &p,const Point &q);
Point operator - (const Point &p) {return Point(x - p.x,y - p.y);}
friend bool operator > (const Point &p,const Point &q);
bool operator < (const Point &q);
// void operator = (Point &p) {this->x=2*p.x;this->y=2*p.y;}
// działa dla p3=p4; p5=p6, ald nie działa np dla p3=p2+p1
// void operator = (const Point &p) {this->x=2*p.x;this->y=2*p.y;}
// działa dla p1=p2 p3=p1+p2, ale nie działa dla p3=p4=p2+p1
Point & operator = (const Point &p) {this->x=p.x;this->y=p.y;return *this;}
// działa dla p3=p4=p2+p1
friend ostream& operator << (ostream &os,const Point &n);
int getX() const {return x;} //metoda wywoływana dla obiektów const
int getY() const {return y;}
friend void PrintPoint1(const Point n); //funkcja zaprzyjaźniona ma dostęp do pól //prywatnych
private:
int x, y;
};
bool Point::operator < (const Point &q)
{
if (x*x+y*y < q.x*q.x+q.y*q.y) return true;
return false;
}
bool operator > (const Point &p,const Point &q)
{
if (p.x*p.x+p.y*p.y > q.x*q.x+q.y*q.y) return true;
return false;
}
Point operator + (const Point &p,const Point &q)
{
Point r;
r.x=p.x+q.x;
r.y=p.y+q.y;
return r;
}
void PrintPoint(const Point n) //zwykła funkcja ma dostęp do metod publicznych klasy
{
cout << n.getX() << " " << n.getY() << endl;
}
void PrintPoint1(const Point n) //funkcja zaprzyjaźniona z klasą
{
cout << n.x << " " << n.y << endl;
}
ostream& operator << (ostream &os,const Point &n)
{
os << n.x << " " << n.y << endl;
return os; // dzięki takiej definicji os może być równe cout, ale
// może być też skojarzone z plikiem
}
int main(void)
{
Point p1(2,2);
Point p2(1,1);
Point p3,p4,p5;
const Point p6;
int a=5,b=10;
p3=p1;
p4=p2;
p5=p3;
p4=p2+p1;
// p3=p2+p1;
// p5=p4;
p3=p4=p5=p2+p1;
cout << p1;
cout << p2;
cout << p3 << p4 << p5; //pisanie na standardowe wyjście
cout << (p2>p1) << endl;
cout << (p2<p1) << endl;
cout << (a<b) << endl;
ofstream outfile; //pisanie do pliku
outfile.open ("test.txt");
outfile << p3;
outfile.close();
}