Advertisement
Guest User

Untitled

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