### What do I need to do to get the correct calculations in this program?

Here is the website for the assignment I am working on:
http://view.samurajdata.se/rsc/5c1dd0b4/

Here is the website for my header file (MixedExpression.h):
http://ideone.com/oJ6mI8

Here is the website for my library source file (MixedExpression.cpp):
http://ideone.com/inEyqe

Here is the website for my calculator client file (Calculator.cpp):
http://ideone.com/EDTWeS

The header file is correct. I got the entire calculator client file working correctly. In the library source file, the GCD() function and the default constructor is correct, and I got the normal constructor, ReadMixedExp(), and printData() working correctly. But I am having trouble with the reduce() function and the add(), subtract(), multiply(), and divide() methods. For these input lines:

 ``12345`` ``````( 1 + 2 / 6 ) + ( 3 + -3 / 9 ) ( 3 + 5 / 9 ) + ( 2 + 3 / 7 ) ( 7 + 5 / 25 ) + ( 4 + -6 / 14 ) ( 3 + 5 / 9 ) - ( 2 + 3 / 7 ) ( 7 + 5 / 25 ) * ( 4 + -6 / 14 )``````

I am supposed to be getting this expected output:

 ``12345`` ``````( 1 + 2 / 6 ) + ( 3 + -3 / 9 ) = ( 4 + 0 / 1 ) ( 3 + 5 / 9 ) + ( 2 + 3 / 7 ) = ( 5 + 62 / 63 ) ( 7 + 1 / 5 ) + ( 3 + 4 / 7 ) = ( 10 + 27 / 35 ) ( 3 + 5 / 9 ) - ( 2 + 3 / 7 ) = ( 1 + 8 / 63 ) ( 7 + 1 / 5 ) * ( 3 + 4 / 7 ) = ( 25 + 5 / 7 )``````

But now all I am getting is this output:

 ``123456`` ``````( 1 + 2 / 6 ) + ( 3 + -3 / 9 ) = ( 27 + 0 / 54 ) ( 3 + 5 / 9 ) + ( 2 + 3 / 7 ) = ( 39 + 0 / 63 ) ( 7 + 5 / 25 ) + ( 4 + -6 / 14 ) = ( 198 + 0 / 350 ) ( 3 + 5 / 9 ) - ( 2 + 3 / 7 ) = ( 3 + 0 / 63 ) ( 7 + 5 / 25 ) * ( 4 + -6 / 14 ) = ( 9800 + 0 / 350 ) ( 7 + 5 / 25 ) * ( 4 + -6 / 14 ) = ( 9800 + 0 / 350 )``````

Also, I'm not sure if I am supposed to print an error code if I read this line:

`( 1 + 0 / 1 ) / ( 0 + 0 / 1 ) `

But most importantly, I'm not sure how to convert the expressions to reduced form and do the calculations correctly, and why is the last line printing twice. Is there anything I need to fix/change in the reduce() function and the four methods and in the calculator client? These are only the last few parts I need help with.
> But I am having trouble with the reduce() function
I you only had listened to your compiler.
You defined a global function `reduce()' not a member function, so `a' `b' and `c' are not related with any object, they are uninitialized so the result is garbage.

> and why is the last line printing twice
Because you are reading incorrectly
 ``123456`` `````` while(!in.eof()) { op1.ReadMixedExp(in); //¿what if you reach eof here? in >> symbol; op2.ReadMixedExp(in); switch(symbol) //you still process as if everything was right ``````
Last edited on
Topic archived. No new replies allowed.