fork download
  1. #include "MixedExpression.h"
  2. #include<iostream>
  3. #include<fstream>
  4. #include<cmath>
  5. using namespace std;
  6.  
  7. long GCD(long x, long y) // Get the greatest common divisor.
  8. {
  9. long remainder; // Holds the remainder.
  10. x = abs(x);
  11. y = abs(y);
  12. while(y != 0)
  13. {
  14. // Get the value of the remainder by dividing y by x.
  15. remainder = x % y;
  16. x = y;
  17. y = remainder;
  18. }
  19. // Return the greatest common divisor.
  20. return x;
  21. }
  22. // Convert a mixed expression to its normal form.
  23. void reduce(void)
  24. {
  25. long a, b, c, x;
  26. long gcd;
  27.  
  28. if(GCD(x,c) > 0)
  29. {
  30. x = a + (b/c);
  31. gcd = GCD(x, c);
  32. x /= gcd;
  33. c /= gcd;
  34. }
  35. }
  36.  
  37. // Set three values in the default constructor to 0.
  38. MixedExpression::MixedExpression()
  39. {
  40. a = 0;
  41. b = 0;
  42. c = 1;
  43. }
  44.  
  45. MixedExpression::MixedExpression(long d, long e, long f)
  46. {
  47. a = d;
  48. b = e;
  49. c = f;
  50. }
  51.  
  52. // Add two values and return the sum.
  53. MixedExpression MixedExpression::add(MixedExpression op)
  54. {
  55. MixedExpression res;
  56. res.a = (a * op.c) + (op.a * c);
  57. res.b = (b/c) + (op.b/op.c);
  58. res.c = (c * op.c);
  59. return res;
  60. }
  61.  
  62. // Subtract two values and return the difference.
  63. MixedExpression MixedExpression::subtract(MixedExpression op)
  64. {
  65. MixedExpression res;
  66. res.a = (a * op.c) - (op.a * c);
  67. res.b = (b/c) - (op.b/op.c);
  68. res.c = (c * op.c);
  69. return res;
  70. }
  71.  
  72. // Multiply two values and return the product.
  73. MixedExpression MixedExpression::multiply(MixedExpression op)
  74. {
  75. MixedExpression res;
  76. res.a = (a * op.c) * (op.a * c);
  77. res.b = (b/c) * (op.b/op.c);
  78. res.c = (c * op.c);
  79. return res;
  80. }
  81.  
  82. // Divide two values and return the quotient.
  83. MixedExpression MixedExpression::divide(MixedExpression op)
  84. {
  85. MixedExpression res;
  86. res.a = (a * op.c) / (op.a * c);
  87. res.b = (b/c) / (op.b/op.c);
  88. res.c = (c * op.c);
  89. return res;
  90. }
  91.  
  92. // Read each value.
  93. void MixedExpression::ReadMixedExp(istream &in)
  94. {
  95. char remove;
  96. in >> remove >> a >> remove >> b >> remove >> c >> remove;
  97. }
  98.  
  99. // Print the results.
  100. void MixedExpression::printData(ostream &out)
  101. {
  102. out << "( " << a << " + " << b << " / " << c << " )";
  103. }
  104.  
  105.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:29: fatal error: MixedExpression.h: No such file or directory
 #include "MixedExpression.h"
                             ^
compilation terminated.
stdout
Standard output is empty