Advertisement
Josif_tepe

Untitled

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