CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2010
    Posts
    23

    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

  2. #2
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    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.

  3. #3
    Join Date
    Nov 2010
    Posts
    23

    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.

  4. #4
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Processing expressions of either infix or postfix

    Quote Originally Posted by youngyou4 View Post
    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

  5. #5
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    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.

  6. #6
    Join Date
    Nov 2010
    Posts
    23

    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.

  7. #7
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Processing expressions of either infix or postfix

    Quote Originally Posted by youngyou4 View Post
    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

  8. #8
    Join Date
    Nov 2008
    Location
    England
    Posts
    748

    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
  •  





Click Here to Expand Forum to Full Width

Featured