Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <cmath>
- #include <cstring>
- #include <cstdlib>
- #include <string>
- #include <vector>
- using namespace std;
- class Fraction {
- private:
- int x, y;
- public:
- void read() {
- char c;
- cin >> x >> c >> y;
- }
- Fraction(int x = 0, int y = 1) {
- this->x = x;
- this->y = y;
- }
- Fraction operator + (const Fraction&s) {
- int a, b;
- b = y * s.y;
- a = x * s.y + y * s.x;
- return Fraction(a, b);
- }
- void show() {
- cout << x << "/" << y;
- }
- };
- int main() {
- Fraction a, b, c;
- a.read();
- b.read();
- c = a + b;
- c.show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement