Question: //VERY VERY URGENT// The template: #include #include using namespace std; struct node{ int value; node *next; }; class Stack{ public: Stack(); void push(int v); void





//VERY VERY URGENT//
The template:
#include
using namespace std;
struct node{ int value; node *next; };
class Stack{ public: Stack(); void push(int v); void pop(); bool isEmpty(); int stackTop(); private: node *top; };
Stack::Stack(){ top=NULL; }
bool Stack::isEmpty(){ return (top== NULL); }
void Stack::push(int v){ node *nn = new node; nn->value = v; nn->next = top; top = nn; }
void Stack::pop(){ if (isEmpty()){ coutnext; } }
int Stack::stackTop(){ if (isEmpty()){ coutvalue; } }
void Q2a_answer(){ char exp[] = "563/-2+"; cout
void Q2b_answer(){ char exp[] = "563/-2+"; cout
void Q2c_answer(){ char exp[] = "563/-2+"; cout
void Q2d_answer(){ char exp[] = "563/-2+"; cout
void Q2e_answer(){ char exp[30]; cout
int main(){ char selection; while (true){ cout>selection; system("CLS"); switch (selection){ case 'a': Q2a_answer(); break; case 'b': Q2b_answer(); break; case 'c': Q2c_answer(); break; case 'd': Q2d_answer(); break; case 'e': Q2e_answer(); break; case 'x': cout The following program, "Test2(2021).cpp" is to evaluate the postfix expression using stack. Open and run the program Test2(2021).cpp". You are required to complete the program by following the Task 1 to Task 5 below. Make sure you are able to run the program and produce the output as shown in Figure 1, before start to answer Task 1 to Task 5. Answer for Question 'a' 'b''c' 'd' 'e' 'x' for exit Selection : Figure 1: Initial output of program Test2(2021).exe Task 1: Complete the code inside Q2a_answer function to print the postfix expression, exp. Figure 2 shows the result of this task. (2 marks) Q2a_answer exp is : 563/-2+ Answer for Question 'a' 'b' 'c' 'd' 'e' 'x' for exit Selection : Figure 2: Expected output for Task 1 Task 2: Complete the code inside Q2b_answer function to print the postfix expression exp. Then, create stack s, and check either stack s is empty or not. Figure 3 shows the result of this task. (3 marks) Task 2: Complete the code inside Q2b_answer function to print the postfix expression exp. Then, create stack s, and check either stack s is empty or not. Figure 3 shows the result of this task. (3 marks) Q2b_answer exp is : 563/-2+ Create a stack s And test empty or not Is the stack empty ? : 1 Answer for Question 'a' 'b' 'c' 'd' 'e' 'x' for exit Selection : Figure 3: Expected output for Task 2 2 Task 3: Complete the code inside Q2c_answer to scan through the postfix expression exp, character by character. If the character is operand, then push it into stack s. If character is operator, just ignore it. After that, display the values stored in stack s. Figure 4 shows the result of this task. (8 marks) Q2c_answer exp is : 563/-2+ exp[0] : 5 exp[1] : 6 exp(2) : 3 exp[5: 2 Create a stacks And test empty or not Is the stack empty ? : 1 Push every operand into stacks Operands stored in stack s 2 3 6 5 Answer for Question 'a' 'b' 'c' 'd' 'e' 'x' for exit Selection : Figure 4: Expected output for Task 3 Task 4: Complete the code inside 92d_answer to scan through the postfix expression exp until end of the expression. If the character is operand, then push it into stack s. If the character is an operator, then get two operands from the stack s, perform the mathematical operation, and push the result back into stack s. Next, get and display the value stored in stack s, which is the final answer. Figure 5 shows the result of this task. (12 marks) Task 5: Complete the code inside Q2e_answer to read the postfix expression, exp from the user using keyboard. Then evaluate and display the final result. Figure 6 shows the result of this task. (5 marks) Q2d answer exp is : 563/-2+ Create a stacks And test empty or not Is the stack empty ? : 1 Push every operands into stacks Final Answer is : 5 Answer for Question 'a' 'b' 'c' 'd' 'e' 'x' for exit Selection : Figure 5: Expected output for Task 4 Q2e_answer Please write the Postfix Expression, then press enter when done 834+2/35 exp is : 834+*2/35+- Length is : 11 Create a stacks Push every operand into stacks Final Answer is : 13 Answer for Question 'a' 'b' 'c' 'd' 'e' 'x' for exit Selection : Figure 6: Expected output for Task 5
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
