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/G9aC9D

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

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

Here are the input lines:

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

Here is my output:

``````( 1 + 1 / 3 ) + ( 2 + 2 / 3 ) = ( 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 )
( 3 + 5 / 9 ) / ( 2 + 3 / 7 ) = ( 1 + 71 / 153 )
( 7 + 1 / 5 ) * ( 3 + 4 / 7 ) = ( 25 + 5 / 7 )
( 4 + 4 / 5 ) * ( 2 + 1 / 2 ) = ( 12 + 0 / 1 )
( 4 + 4 / 5 ) * ( 2 + 1 / 2 ) = ( 12 + 0 / 1 )
``````

My question is: All of my code is correct, except the last line is printing twice. This is the only part I need help correcting. I know I should not use the eof() member function, but I'm not sure what else to use. How can I fix this small part?

If you had an extra blank line ((or even a few spaces at the end of the last line) at the end of you dtata file then the !eof end condition in the while loop wouldn't be triggered, however the the request for input in ReadMixedExp would fail.

In this case you would go round the loop again but would fail to read new values for op1 and op2, they stay unchanged and you get an extra line of output.

You should have ReadMixedExp return some sort of status to indicate if the function correctly and then if it fails reading either op1 or op2 end the loop.

P.S. I personally don't really like having to go off to another website I know nothing about to retrieve your source, please put it in the post in future.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.