Question: please use the code in the description and follow my directions exactly do this in C++. USE MY CODE THAT I HAVE PLEASE AND JUST

please use the code in the description and follow my directions exactly do this in C++. USE MY CODE THAT I HAVE PLEASE AND JUST ADD THE NEW CODE!!!

Write a function postFixEval for stack-based evaluation of postfix expressions. The program reads postfix expressions and prints their values. Each input expression should be entered on its own line, and the program should terminate when the user enters a blank line. Assume that there are only binary operators and that the expressions contain no variables. Your program should use a tack. Here are sample input-output pairs.

78 78

78 6 + 84

78 6 + 9 2 - / 12

#include  #include  #include  #include  using namespace std; // skipWhiteSpace for Skiping whitespace in an input stream. * void skipWhiteSpace(istream& in) { while (in.good() && isspace(in.peek()) ) { // Read and discard the space character in.get(); } } // // postFixEval // If the next token in the input is an integer, read // the integer and push it on the stack; but if it is // an operator, pop the last two values from the stack // and apply the operator, and push the result onto // the stack. At the end of the string, the lone // on the stack is the result. // int postFixEval(string str) { istringstream in = istringstream(str); stack postFixStack; skipWhiteSpace(in); while (in) {
} return postFixStack.top(); } int main() { string input; while (true) { cout << "Enter a postfix expression, or press ENTER to quit: "; getline(cin, input); if (input.length() == 0) { break; } int number = postFixEval(input); cout << "The value of " << input << " is " << number << endl; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!