Josif_tepe

Untitled

Sep 12th, 2026
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Point {
  5. private:
  6.     int x, y;
  7. public:
  8.     Point() {}
  9.     Point(int x, int y) {
  10.         this->x = x;
  11.         this->y = y;
  12.     }
  13.    
  14.     Point(const Point &tmp) {
  15.         this->x = tmp.x;
  16.         this->y = tmp.y;
  17.     }
  18.    
  19.     ~Point() {}
  20.    
  21.     Point operator + (Point p) {
  22.         return Point(x + p.x, y + p.y);
  23.     }
  24.    
  25.     Point operator - (Point p) {
  26.         return Point(x - p.x, y - p.y);
  27.     }
  28.    
  29.     Point operator * (Point p) {
  30.         return Point(x * p.x, y * p.y);
  31.     }
  32.    
  33.     Point operator / (Point p) {
  34.         return Point(x / p.x, y / p.y);
  35.     }
  36.    
  37.    
  38.     Point & operator += (Point p) {
  39.         x += p.x;
  40.         y += p.y;
  41.        
  42.         return *this;
  43.     }
  44.    
  45.     Point & operator -= (Point p) {
  46.         x -= p.x;
  47.         y -= p.y;
  48.        
  49.         return *this;
  50.     }
  51.      
  52.     Point & operator *= (Point p) {
  53.         x *= p.x;
  54.         y *= p.y;
  55.        
  56.         return *this;
  57.     }
  58.    
  59.     Point & operator /= (Point p) {
  60.         x /= p.x;
  61.         y /= p.y;
  62.        
  63.         return *this;
  64.     }
  65.    
  66.     bool operator < (Point p) {
  67.         if(x < p.x and y < p.y) {
  68.             return true;
  69.         }
  70.         return false;
  71.     }
  72.    
  73.     bool operator > (Point p) {
  74.         if(x > p.x and y > p.y) {
  75.             return true;
  76.         }
  77.         return false;
  78.     }
  79.    
  80.    
  81.     void print() {
  82.         cout << x << " " << y << endl;
  83.     }
  84.    
  85.     friend ostream & operator << (ostream & stream, Point & p);
  86.     friend istream & operator >> (istream & stream, Point & p);
  87. };
  88.  
  89. ostream & operator << (ostream & stream, Point & p) {
  90.     stream << "X: " << p.x << endl;
  91.     stream << "Y: " << p.y << endl;
  92.    
  93.     return stream;
  94. }
  95.  
  96. istream & operator >> (istream & stream, Point & p) {
  97.     stream >> p.x >> p.y;
  98.     return stream;
  99. }
  100.  
  101. int main() {
  102.    
  103.    
  104.    
  105.     Point A;
  106.     Point B;
  107.    
  108.     cin >> A >> B;
  109.    
  110.     Point C = A + B;
  111.     Point C2 = A - B;
  112.     Point C3 = A * B;
  113.     Point C4 = A / B;
  114.    
  115.     C.print();
  116.     C2.print();
  117.     C3.print();
  118.     C4.print();
  119.    
  120.     Point D(4, 5);
  121.     D += A;
  122.    
  123.     D.print();
  124.    
  125.     D -= B;
  126.     D.print();
  127.    
  128.    
  129.     D *= A;
  130.     D.print();
  131.    
  132.     D /= B;
  133.     D.print();
  134.    
  135.     if(A < B) {
  136.         cout << "A e pomalo od B" << endl;
  137.     }
  138.    
  139.    
  140.     cout << A << endl;
  141.     return 0;
  142. }
  143.  
Advertisement
Add Comment
Please, Sign In to add comment