Question: I need the double evalPostfix(string& input) function completed below. It should check for divide by zero error and an invalid expression. Sample data should be:

I need the double evalPostfix(string& input) function completed below. It should check for divide by zero error and an invalid expression. Sample data should be:

.5 .25 /

2.5 3.7 + 8.5 *

5 3.12 * + 4 - 5 +

25 347.8 5 * + 5 /

2 3 /

// Reads a series of postfix notation equations from the user, // processes them into a stack, evaluates them, then presents the value to // the user. #include  #include  #include  // STL stack class #include  // Provides EXIT_SUCCESS #include  // Provides assert using namespace std; // Precondition: input string is valid and has data to process // Postcondition: input string is processed as postfix arithmetic // expression made up of nonnegative double numbers and the // four operations + - * and /. STL Stack holds nonnegative // double numbers for evaluation. If everything went okay, then // the return value answer is set to the value of this // expression. Evaluation algorithm found in Figure 7.10 of // textbook or Lecture Slide 18 double evalPostfix(string& input) { // TO DO return 0.0; } // main controlling function int main() { double answer; string exp; cout << "Enter the postfix expression: "; getline(cin, exp); while (exp.length() > 0) { answer = evalPostfix(exp); cout << "==> evaluates to " << answer << endl; cout << "Enter another postfix expression or  to end: "; getline(cin, exp); } return EXIT_SUCCESS; }

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!