Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <cstring>
  5. using namespace std;
  6. class faction{
  7. int x;
  8. int y;
  9. public:
  10. faction(int a, int b){
  11. x=a;
  12. y=b;
  13. }
  14. faction(){
  15. x=0;
  16. y=0;
  17. }
  18. void setFrac(string a){
  19. if(a.size()==3){
  20. switch(a[0]){
  21. case '/':
  22. return;
  23. case '1':
  24. x=1;
  25. break;
  26. case '2':
  27. x=2;
  28. break;
  29. case '3':
  30. x=3;
  31. break;
  32. case '4':
  33. x=4;
  34. break;
  35. case '5':
  36. x=5;
  37. break;
  38. case '6':
  39. x=6;
  40. break;
  41. case '7':
  42. x=7;
  43. break;
  44. case '8':
  45. x=8;
  46. break;
  47. case '9':
  48. x=9;
  49. break;
  50. case '0':
  51. x=0;
  52. break;
  53. default:
  54. return;
  55. }
  56. switch(a[1]){
  57. case '/':
  58. break;
  59. default:
  60. return;
  61. }
  62. switch(a[2]){
  63. case '/':
  64. return;
  65. case '1':
  66. y=1;
  67. break;
  68. case '2':
  69. y=2;
  70. break;
  71. case '3':
  72. y=3;
  73. break;
  74. case '4':
  75. y=4;
  76. break;
  77. case '5':
  78. y=5;
  79. break;
  80. case '6':
  81. y=6;
  82. break;
  83. case '7':
  84. y=7;
  85. break;
  86. case '8':
  87. y=8;
  88. break;
  89. case '9':
  90. y=9;
  91. break;
  92. case '0':
  93. y=0;
  94. break;
  95. default:
  96. return;
  97. }
  98. }
  99. }
  100. void getFrac(){
  101. cout<<x<<"/"<<y<<endl;
  102. }
  103. int getX(){
  104. return x;
  105. }
  106. int getY(){
  107. return y;
  108. }
  109. void sumFrac(faction a){
  110. x=x+a.getX();
  111. y=y+a.getY();
  112. getFrac();
  113. }
  114. };
  115.  
  116. int main() {
  117. faction a(0, 0);
  118. faction b(0, 0);
  119. faction c(0, 0);
  120. string a1="y";
  121. string b1;
  122. while(a1=="y"){
  123. cin>>b1;
  124. a.setFrac(b1);//
  125. cin>>b1;
  126. b.setFrac(b1);//
  127. a.sumFrac(b);//
  128. cout<<"Wanna continue? y/n"<<endl;
  129. a1="n";
  130. cin>>a1;
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement