Advertisement
syasinaeg

Матевосов Дима: "Дроби: сравнение с вещественным числом"

Mar 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <cstdlib>
  6. #include <string>
  7. #include <vector>
  8. using namespace std;
  9.  
  10. class Fraction {
  11. private:
  12.     int x, y;
  13. public:
  14.     void read() {
  15.         char c;
  16.         cin >> x >> c >> y;
  17.     }
  18.     Fraction(int x = 0, int y = 1) {
  19.         this->x = x;
  20.         this->y = y;
  21.     }
  22.     Fraction operator + (const Fraction&s) {
  23.         int a, b;
  24.         b = y * s.y;
  25.         a = x * s.y + y * s.x;
  26.         return Fraction(a, b);
  27.     }
  28.     void show() {
  29.         cout << x << "/" << y;
  30.     }
  31. };
  32.  
  33. int main() {
  34.     Fraction a, b, c;
  35.     a.read();
  36.     b.read();
  37.     c = a + b;
  38.     c.show();
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement