Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ #include #include using namespace std; const int MAXSIZE = 5; class Stack { public: Stack(); bool Empty(); void Push(int item); void Pop(); int Top();

C++

#include #include using namespace std;

const int MAXSIZE = 5; class Stack { public: Stack(); bool Empty(); void Push(int item); void Pop(); int Top(); void displayStack(); private: int stk[MAXSIZE]; int top; }; bool isNumber(string, int &); int calculate(int, int, string); int main() { Stack expStack; string inToken; int num, oprd1, oprd2, result; // *** enter your code here - ref to the steps // *** in the lab sheet.

system("Pause"); return 0; } Stack::Stack() { top = 0; } bool Stack::Empty() { if (top == 0) return true; else return false; } void Stack::Push(int item) { stk[top] = item; top++; } void Stack::Pop() { top--; } int Stack::Top() { return stk[top]; } void Stack::displayStack() { for (int i = 0; i > number; if (ss.good()) return false; else if (number == 0 && inStr[0] != '0') return false; else return true; } /* This function will use switch statement check the first charactor in op to see if it is "=". Then it will calculate and return the result. Assume there are only 4 operators +, -, *, / */ int calculate(int num1, int num2, string op) { // *** write your code here }

image text in transcribed

3 (20 points+20 Bonus points if correctly done) Given a Stack expStack Write code to evaluate any postfix expression provided by the user. please end the expression by an "sign. To simplify the code, we do not check for error expressions and assume user always type in To work on expression "2 5 + 4-9e illdo 1. Prompt user for enter the expression 2. Get one token from the expression (2, in this case), if there is one 3. if the token is an , break the loop if the token is an integer push the token into the stack print the number out else (the token must be one of the four operations +,-, '*, ) pop) twice and do the math on the operator push the result back to the stack 5. 6. loop back to line 2 pop the stack, the number should be the final result 12]

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

Essential SQLAlchemy Mapping Python To Databases

Authors: Myers, Jason Myers

2nd Edition

1491916567, 9781491916568

More Books

Students also viewed these Databases questions