Answered step by step
Verified Expert Solution
Link Copied!

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions