Advertisement
Josif_tepe

Untitled

Oct 28th, 2023
563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. class Point {
  5.     int x;
  6.     int y;
  7.    
  8. public:
  9.     Point() {}
  10.     Point(int _x, int _y) {
  11.         x = _x;
  12.         y = _y;
  13.     }
  14.     void set_x(int _x) {
  15.         x = _x;
  16.     }
  17.     void set_y(int _y) {
  18.         y = _y;
  19.     }
  20.     int get_x() {
  21.         return x;
  22.     }
  23.     int get_y() {
  24.         return y;
  25.     }
  26.    
  27.     Point operator + (Point tmp) {
  28.         Point result(x + tmp.x, y + tmp.y);
  29.         return result;
  30.     }
  31.     Point operator - (Point tmp) {
  32.         Point result(x - tmp.x, y - tmp.y);
  33.         return result;
  34.     }
  35.     Point operator * (Point tmp) {
  36.         Point result(x * tmp.x, y * tmp.y);
  37.         return result;
  38.     }
  39.     Point operator / (Point tmp) {
  40.         Point result(x / tmp.x, y / tmp.y);
  41.         return result;
  42.     }
  43.     bool operator < (Point tmp) {
  44.         if(x < tmp.x and y < tmp.y) {
  45.             return true;
  46.         }
  47.         else {
  48.             return false;
  49.         }
  50.     }
  51.     bool operator <= (Point tmp) {
  52.         if(x <= tmp.x and y <= tmp.y) {
  53.             return true;
  54.         }
  55.         else {
  56.             return false;
  57.         }
  58.     }
  59.     bool operator > (Point tmp) {
  60.         if(x > tmp.x and y > tmp.y) {
  61.             return true;
  62.         }
  63.         else {
  64.             return false;
  65.         }
  66.     }
  67.     bool operator >= (Point tmp) {
  68.         if(x >= tmp.x and y >= tmp.y) {
  69.             return true;
  70.         }
  71.         else {
  72.             return false;
  73.         }
  74.     }
  75.     bool operator == (Point tmp) {
  76.         if(x == tmp.x and y == tmp.y) {
  77.             return true;
  78.         }
  79.         else {
  80.             return false;
  81.         }
  82.     }
  83.     bool operator != (Point tmp) {
  84.         if(x != tmp.x or y != tmp.y) {
  85.             return true;
  86.         }
  87.         else {
  88.             return false;
  89.         }
  90.     }
  91.     friend ostream & operator << (ostream & stream, Point tmp);
  92. };
  93. ostream & operator << (ostream & stream, Point tmp) {
  94.     stream << tmp.x << " ";
  95.     stream << tmp.y;
  96.     return stream;
  97. }
  98. int main()
  99. {
  100.     Point p1(4, 4);
  101.     Point p2(5, 3);
  102.    
  103.     cout << p1 << endl;
  104.     cout << p2 << endl;
  105.     return 0;
  106. }
  107.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement