Advertisement
Josif_tepe

Untitled

Apr 1st, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3.  
  4. using namespace std;
  5.  
  6. class Point {
  7. private:
  8.     int x, y;
  9.     int niza[5];
  10. public:
  11.     Point() {}
  12.     Point(int _x, int _y) {
  13.         x = _x;
  14.         y = _y;
  15.     }
  16.     ~Point() {}
  17.     void print() {
  18.         cout << x << " " << y << endl;
  19.     }
  20.     Point operator + (Point p) {
  21.         Point temp;
  22.         temp.x = x + p.x;
  23.         temp.y = y + p.y;
  24.         return temp;
  25.     }
  26.     Point operator - (Point p) {
  27.         Point temp;
  28.         temp.x = x - p.x;
  29.         temp.y = y - p.y;
  30.         return temp;
  31.     }
  32.     Point operator * (Point p) {
  33.         Point temp;
  34.         temp.x = x * p.x;
  35.         temp.y = y * p.y;
  36.         return temp;
  37.     }
  38.     Point operator / (Point p) {
  39.         Point temp;
  40.         temp.x = x / p.x;
  41.         temp.y = y / p.y;
  42.         return temp;
  43.     }
  44.     bool operator < (Point p) {
  45.         if(x < p.x and y < p.y) {
  46.             return true;
  47.         }
  48.         return false;
  49.     }
  50.     bool operator > (Point p) {
  51.         if(x > p.x and y > p.y) {
  52.             return true;
  53.         }
  54.         return false;
  55.     }
  56.     bool operator <= (Point p) {
  57.         if(x <= p.x and y <= p.y) {
  58.             return true;
  59.         }
  60.         return false;
  61.     }
  62.     bool operator >= (Point p) {
  63.         if(x >= p.x and y >= p.y) {
  64.             return true;
  65.         }
  66.         return false;
  67.     }
  68.     bool operator == (Point p) {
  69.         if(x == p.x and y == p.y) {
  70.             return true;
  71.         }
  72.         return false;
  73.     }
  74.     bool operator != (Point p) {
  75.         if(x == p.x and y == p.y) {
  76.             return true;
  77.         }
  78.         return false;
  79.     }
  80.     Point& operator += (Point p) {
  81.         x += p.x;
  82.         y += p.y;
  83.         return *this;
  84.     }
  85.     Point& operator -= (Point p) {
  86.         x -= p.x;
  87.         y -= p.y;
  88.         return *this;
  89.     }
  90.     Point& operator *= (Point p) {
  91.         x *= p.x;
  92.         y *= p.y;
  93.         return *this;
  94.     }
  95.     Point& operator /= (Point p) {
  96.         x /= p.x;
  97.         y /= p.y;
  98.         return *this;
  99.     }
  100.     Point& operator ++ (int p) { //postfix
  101.         x++;
  102.         y++;
  103.         return *this;
  104.     }
  105.     Point& operator ++ () { // prefix
  106.         ++x;
  107.         ++y;
  108.         return *this;
  109.     }
  110.     Point& operator -- (int p) { //postfix
  111.         x--;
  112.         y--;
  113.         return *this;
  114.     }
  115.     Point& operator -- () {
  116.         --x;
  117.         --y;
  118.         return *this;
  119.     }
  120.     Point& operator = (Point p) {
  121.         x = p.x;
  122.         y = p.y;
  123.         return *this;
  124.     }
  125.     void set_niza(int a[5], int n) {
  126.         for(int i = 0; i < n; i++) {
  127.             niza[i] = a[i];
  128.         }
  129.     }
  130.     int& operator [] (int indeks) {
  131.         return niza[indeks];
  132.     }
  133.     friend ostream& operator << (ostream &stream, Point p);
  134.     friend istream& operator >> (istream &stream, Point &p);
  135. };
  136. ostream& operator << (ostream &stream, Point p) {
  137.     stream << "X: " << p.x << endl;
  138.     stream << "Y: " << p.y << endl;
  139.     return stream;
  140. }
  141. istream& operator >> (istream &stream, Point &p) {
  142.     stream >> p.x;
  143.     stream >> p.y;
  144.     return stream;
  145. }
  146.  
  147. int main()
  148. {
  149.    
  150.    
  151.     Point p1;
  152.     cin >> p1;
  153.     int a[5] = {1, 2, 3, 4, 5};
  154.     p1.set_niza(a, 5);
  155.     cout << p1[2] << endl;
  156.     return 0;
  157. }
  158.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement