Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started