Advertisement
Josif_tepe

Untitled

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