Josif_tepe

Untitled

Sep 10th, 2025
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Point {
  6. private:
  7.     float a, b;
  8.  
  9. public:
  10.     Point() {}
  11.     Point(float _a, float _b) {
  12.         a = _a;
  13.         b = _b;
  14.     }
  15.    
  16.     Point operator + (Point p) {
  17.         Point res(a + p.a, b + p.b);
  18.         return res;
  19.     }
  20.    
  21.     Point operator - (Point p) {
  22.         Point res(a - p.a, b - p.b);
  23.         return res;
  24.     }
  25.     Point operator * (Point p) {
  26.         Point res(a * p.a, b * p.b);
  27.         return res;
  28.     }
  29.     Point operator / (Point p) {
  30.         Point res(a / p.a, b / p.b);
  31.         return res;
  32.     }
  33.    
  34.     void print() {
  35.         cout << a << " " << b << endl;
  36.     }
  37.    
  38. };
  39. int main() {
  40.    
  41.    
  42.     Point a(4.0, 5.6);
  43.    
  44.     Point b(3.7, 6.3);
  45.    
  46.     Point c_plus = a + b;
  47.     Point c_minus = a - b;
  48.     Point c_multiply = a * b;
  49.     Point c_divide = a / b;
  50.    
  51.     c_plus.print();
  52.     c_minus.print();
  53.     c_multiply.print();
  54.     c_divide.print();
  55.    
  56.    
  57.      return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment