Advertisement
Josif_tepe

Untitled

Jan 20th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 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.  
  19.     int get_x() {
  20.         return x;
  21.     }
  22.     int get_y() {
  23.         return y;
  24.     }
  25.  
  26.     void set_x(int _x) {
  27.         x = _x;
  28.     }
  29.     void set_y(int _y) {
  30.         y = _y;
  31.     }
  32.  
  33.     Point operator + (Point tmp) {
  34.         Point res(x + tmp.x, y + tmp.y);
  35.         return res;
  36.     }
  37.     Point operator - (Point tmp) {
  38.         Point res(x - tmp.x, y - tmp.y);
  39.         return res;
  40.     }
  41.     Point operator * (Point tmp) {
  42.         Point res(x * tmp.x, y * tmp.y);
  43.         return res;
  44.     }
  45.     Point operator / (Point tmp) {
  46.         Point res(x / tmp.x, y / tmp.y);
  47.         return res;
  48.     }
  49.    
  50.     void print() {
  51.         cout << x << " " << y << endl;
  52.     }
  53. };
  54. int main()
  55. {
  56.     Point p1(2, 3);
  57.     Point p2(4, 5);
  58.  
  59.     Point p3 = p1 + p2;
  60.     p3.print();
  61.  
  62.     Point p4 = p1 - p2;
  63.     p4.print();
  64.    
  65.     Point p5 = p1 * p2;
  66.     p5.print();
  67.    
  68.     Point p6 = p1 / p2;
  69.     p6.print();
  70.     return 0;
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement