Advertisement
Josif_tepe

Untitled

Mar 24th, 2021
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.07 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Dropka{
  6. private:
  7.     int a, b;
  8. public:
  9.     Dropka(int _a = 1, int _b = 1) {
  10.         a = _a;
  11.         b = _b;
  12.     }
  13.     Dropka(const Dropka &d) {
  14.         a = d.a;
  15.         b = d.b;
  16.     }
  17.     Dropka& operator = (const Dropka &d) {
  18.         a = d.a;
  19.         b = d.b;
  20.         return *this;
  21.     }
  22.     ~Dropka() {
  23.        
  24.     }
  25.     Dropka& operator += (const Dropka &d) {
  26.         int zi = b * d.b;
  27.         a *= (zi / d.b);
  28.         int tmp_a = d.a * (zi / b);
  29.         a += tmp_a;
  30.         b = zi;
  31.         return *this;
  32.     }
  33.     Dropka& operator *= (const Dropka &d) {
  34.         a *= d.a;
  35.         b *= d.b;
  36.         return *this;
  37.     }
  38.     Dropka& operator /= (const Dropka &d) {
  39.         a *= d.b;
  40.         b *= d.a;
  41.         return *this;
  42.     }
  43.    
  44.     int get_a() const {
  45.         return a;
  46.     }
  47.     int get_b() const {
  48.         return b;
  49.     }
  50.    
  51. };
  52. int main() {
  53.     Dropka d1(2, 3);
  54.     Dropka d2(3, 4);
  55.    
  56.     d1 /= d2;
  57.    
  58.     cout << d1.get_a() << " " << d1.get_b() << endl;
  59.     return 0;
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement