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