Advertisement
Josif_tepe

Untitled

Jul 9th, 2025
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 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. };
  70.  
  71. int main() {
  72.     Point p1(15, 7);
  73.     Point p2(3, 2);
  74.  
  75.     p1 /= p2;
  76.  
  77.     p1.print();
  78.  
  79.     return 0;
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement