If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Re: Processing expressions of either infix or postfix

Did you read the link you posted. Its all explained there or theres the RPN wiki

Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors. Always use [code] code tags [/code] to make code legible and preserve indentation.Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.

Re: Processing expressions of either infix or postfix

Yes i did read it, but how am i suppose to write the assign9.cpp ? I don't want the code but like the logic on what i need would help.

The logic is all there in the link. What is there that you don't understand?

The goal of a computer programming assignment is to see if you can translate algorithmic, logical steps into a program. Any other help beyond showing you the algorithm/logic is asking us to write the code for you.

Re: Processing expressions of either infix or postfix

One implementation might store the data in a linked list, while another might store the data in a dynamically allocated array. For this assignment, we will use a dynamically allocated array.

Every time I read an assignment that asks for a student to use a dynamically allocated array (especially when pointing out a standard container works just as well), a puppy dies.

Any ways, there is not much we can do for you if you don't understand what to do after having read about RPN. We can help with the code, the code logic, or just getting you started, but you need to input the actual logic behind what you want to do.

Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Re: Processing expressions of either infix or postfix

int evalExp( const string & )

This function evaluates only postfix expressions and returns the result of the expression. The argument to this function is a string that contains a postfix expression. In order for this function to be implemented correctly, you will need to create a local stack that can hold integers.

In order to evaluate the postfix expression you will process it from left to right, character by character, until you reach the end.

If the current postfix character is a digit, push its integer value onto the integer stack.

Otherwise, if the current postfix character is an operator, pop the top two elements from the stack, apply the operator to the two values from the stack, and then push the result onto the integer stack. Do not forget that the first item to come off the stack will be the right operand, and then it will be followed by the left.

Once the entire postfix expression has been processed, there should be one value left on the stack. It's the final result of the expression. This should be popped off the stack and returned to the calling routine.

Code:

int evalExp (const string &)
I dont know where to even start from here. I understand i have to create a empty stack but i dont even know where to begin.

Re: Processing expressions of either infix or postfix

you can make an istringstream object from the string then parse from it two ints and a char. push the ints on the stack. switch on the char to do the right thing in the appropriate case and then return the result.

Get Microsoft Visual C++ Express here or CodeBlocks here.
Get STLFilt here to radically improve error messages when using the STL.
Get these two can't live without C++ libraries, BOOST here and Loki here.
Check your code with the Comeau Compiler and FlexeLint for standards compliance and some subtle errors. Always use [code] code tags [/code] to make code legible and preserve indentation.Do not ask for help writing destructive software such as viruses, gamehacks, keyloggers and the suchlike.