-
November 21st, 2010, 06:46 PM
#1
Processing expressions of either infix or postfix
Hey, I'm working on a program for class and I have part one of the assignment written but I'm not quite understanding this expression of infix or postfix.
This is the link to the assignment 9.
part 1 is completed but part 2 I just dont understand.
If anyone could help explain and help me out
http://faculty.cs.niu.edu/~byrnes/cs...ms/241pgm9.htm
-
November 21st, 2010, 07:19 PM
#2
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.
-
November 21st, 2010, 07:27 PM
#3
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.
-
November 21st, 2010, 07:39 PM
#4
Re: Processing expressions of either infix or postfix
Originally Posted by youngyou4
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.
Regards,
Paul McKenzie
-
November 22nd, 2010, 02:35 AM
#5
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.
-
November 22nd, 2010, 06:38 PM
#6
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.
-
November 22nd, 2010, 07:27 PM
#7
Re: Processing expressions of either infix or postfix
Originally Posted by youngyou4
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.
Code:
#include <stack>
int main()
{
std::stack<int> IntStack; // an empty stack of integers
}
Regards,
Paul McKenzie
-
November 22nd, 2010, 07:34 PM
#8
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|