Advertisement
Josif_tepe

Untitled

Nov 7th, 2021
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. class Point{
  5. private:
  6.     int x, y;
  7. public:
  8.     Point() {}
  9.     Point(int _x, int _y) {
  10.         x = _x;
  11.         y = _y;
  12.     }
  13.     Point operator + (Point p) {
  14.         return Point(x + p.x, y + p.y);
  15.     }
  16.     Point operator + (int i) {
  17.         return Point(x + i, y + i);
  18.     }
  19.     void print() {
  20.         cout << x << " " << y << endl;
  21.     }
  22.    
  23. };
  24. int main()
  25. {
  26.     Point p1(1, 5);
  27.     Point p2(2, 3);
  28.    
  29.     Point p3 = p1 + 2;
  30.    
  31.     p3.print();
  32.     return 0;
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement