Advertisement
Josif_tepe

Untitled

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