Advertisement
Guest User

Untitled

a guest
Mar 24th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 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. class point
  10. {
  11. public:
  12. int x, y;
  13.  
  14. void set(int x, int y){
  15. this->x = x;
  16. this->y = y;
  17. }
  18. };
  19. void zero(int w)
  20. {
  21. if(w >= 10 && w <= 99)
  22. cout << "0" << w;
  23. if(w <= 9)
  24. cout << "00" << w;
  25. if(w >= 100)
  26. cout << w;
  27. }
  28. class Fraction{
  29. private:
  30. int x, y;
  31. char q, w;
  32. int q1, q2, w1, w2;
  33. public:
  34. void read(){
  35. cin >> q1 >> q >> q2;
  36. x = q1;
  37. y = q2;
  38. cin >> w1 >> w >> w2;
  39. }
  40. Fraction(int x = 0, int y = 1){
  41. this->x=x;
  42. this->y=y;
  43. }
  44. Fraction operator + (const Fraction&s){
  45. int a, b;
  46. b=y*(w2);
  47. a=x*(w2)+(w1)*y;
  48. return Fraction(a,b);
  49. }
  50. void show(){
  51. cout << x << "/" << y;
  52. }
  53. };
  54.  
  55. int main() {
  56. Fraction a,b, c;
  57. a.read();
  58. c = a+b;
  59. c.show();
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement