Advertisement
Josif_tepe

Untitled

Mar 31st, 2021
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Point {
  6. private:
  7.     int x, y;
  8. public:
  9.     Point() {}
  10.     Point(int _x, int _y) {
  11.         x = _x;
  12.         y = _y;
  13.     }
  14.     Point(const Point &tmp) {
  15.         x = tmp.x;
  16.         y = tmp.y;
  17.     }
  18.     ~Point() {}
  19.    
  20.     Point& operator ++ (int p) {
  21.         x++;
  22.         return *this;
  23.     }
  24.     Point& operator -- (int p) {
  25.         y--;
  26.         return *this;
  27.     }
  28.     Point& operator = (const Point &tmp) {
  29.         x = tmp.x;
  30.         y = tmp.y;
  31.         return *this;
  32.     }
  33.     Point& operator += (Point tmp) {
  34.         x += tmp.x;
  35.         y += tmp.y;
  36.         return *this;
  37.     }
  38.     Point& operator -= (Point tmp) {
  39.         x -= tmp.x;
  40.         y -= tmp.y;
  41.         return *this;
  42.     }
  43.     Point& operator *= (Point tmp) {
  44.         x *= tmp.x;
  45.         y *= tmp.y;
  46.         return *this;
  47.     }
  48.     Point& operator /= (Point tmp) {
  49.         x /= tmp.x;
  50.         y /= tmp.y;
  51.         return *this;
  52.     }
  53.     int get_x() {
  54.         return x;
  55.     }
  56.     int get_y() {
  57.         return y;
  58.     }
  59. };
  60.  
  61. int main() {
  62.  
  63.     Point p(10, 5);
  64.     Point p2(2, 5);
  65.     p -= p2;
  66.     cout << p.get_x() << endl;
  67.     cout << p.get_y() << endl;
  68.     return 0;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement