Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cstdio>
  4.  
  5. using namespace std;
  6.  
  7. class Drob
  8. {
  9. public:
  10.     int chisl, znam;
  11.  
  12.     Drob() : chisl(1), znam(1) {}
  13.  
  14.     Drob(int chisl, int znam) : chisl(chisl), znam(znam) {}
  15.  
  16.     double value()
  17.     {
  18.         return ((double)chisl) / znam;
  19.     }
  20.  
  21.     void print()
  22.     {
  23.         cout << chisl << "/" << znam;
  24.     }
  25.  
  26.     Drob add(Drob a)
  27.     {
  28.         int tchisl = chisl * a.znam + a.chisl * znam;
  29.         int tznam = znam * a.znam;
  30.        
  31.         return Drob(tchisl, tznam);
  32.     }
  33. };
  34.  
  35. int main()
  36. {
  37.     //freopen("output.txt", "w", stdout);
  38.  
  39.     Drob a;
  40.     a.print();
  41.     cout << "\n";
  42.  
  43.     Drob b(3, 5);
  44.     b.print();
  45.     cout << "\n";
  46.  
  47.     Drob c = a.add(b);
  48.     c.print();
  49.     cout << "\n";
  50.  
  51.     //getc(stdin);
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement