fork download
  1. #include "MixedExpression.h"
  2. #include<iostream>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6. long GCD(long x, long y) // Get the greatest common divisor.
  7. {
  8. long remainder; // Holds the remainder.
  9. while(y != 0)
  10. {
  11. // Get the value of the remainder by dividing y by x.
  12. remainder = x % y;
  13. x = y;
  14. y = remainder;
  15. }
  16. // Return the greatest common divisor.
  17. return x;
  18. }
  19. // Convert a mixed expression to its normal form.
  20. void reduce(void)
  21. {
  22. long a, b, c, x;
  23. long gcd;
  24. x = a + (b/c);
  25. gcd = GCD(x, c);
  26. x /= gcd;
  27. c /= gcd;
  28. }
  29.  
  30. // Set three values in the default constructor to 0.
  31. MixedExpression::MixedExpression()
  32. {
  33. a = 0;
  34. b = 0;
  35. c = 1;
  36. }
  37.  
  38. MixedExpression::MixedExpression(long d, long e, long f)
  39. {
  40. a = d;
  41. b = e;
  42. c = f;
  43. }
  44.  
  45. // Add two values and return the sum.
  46. MixedExpression MixedExpression::add(MixedExpression op)
  47. {
  48. MixedExpression res;
  49. res.a = (((a * c)/c) + (b/c)) + (((op.a * op.c)/op.c) + (op.b/op.c));
  50. return res;
  51. }
  52.  
  53. // Subtract two values and return the difference.
  54. MixedExpression MixedExpression::subtract(MixedExpression op)
  55. {
  56. MixedExpression res;
  57. res.a = (((a * c)/c) + (b/c)) - (((op.a * op.c)/op.c) + (op.b/op.c));
  58. return res;
  59. }
  60.  
  61. // Multiply two values and return the product.
  62. MixedExpression MixedExpression::multiply(MixedExpression op)
  63. {
  64. MixedExpression res;
  65. res.a = (((a * c)/c) + (b/c)) * (((op.a * op.c)/op.c) + (op.b/op.c));
  66. return res;
  67. }
  68.  
  69. // Divide two values and return the quotient.
  70. MixedExpression MixedExpression::divide(MixedExpression op)
  71. {
  72. MixedExpression res;
  73. res.a = (((a * c)/c) + (b/c)) / (((op.a * op.c)/op.c) + (op.b/op.c));
  74. return res;
  75. }
  76.  
  77. // Read each value while not at the end of the file.
  78. void MixedExpression::ReadMixedExp(istream &in)
  79. {
  80. in >> a >> b >> c;
  81. }
  82.  
  83. // Print the results.
  84. void MixedExpression::printData(ostream &out)
  85. {
  86. out << "( " << a << " + " << b << " / " << c << " )" << endl;
  87. }
  88.  
  89.  
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