Advertisement
Josif_tepe

Untitled

Mar 31st, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 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.     friend ostream& operator << (ostream &stream, Point tmp);
  60. };
  61. ostream& operator << (ostream &stream, Point tmp) {
  62.     stream << tmp.x << " " << tmp.y << endl;
  63.     return stream;
  64. }
  65. int main() {
  66.  
  67.     Point p(10, 5);
  68.     Point p2(2, 5);
  69.     p -= p2;
  70.     cout << p << endl;
  71.     // ostream
  72.     return 0;
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement