The problem “Darray stack” is splitted into 2 subproblems:
You should solve the former subproblem first.
In this subproblem, you are asked to implement a class, Postfix_calculator, which calculates a postfix expression using the Darray_stack class you have implemented in "13896".
Here is the structure of Postfix_calculator:
Postfix_calculator contains 2 data members:
You only have to implement the member function void calculate(), which calculates the postfix expression using Darray_stack st and stores the final result on the top of Darray_stack st.
The first line is a string which only contains digits, representing the input of the verify function.
The second line is a postfix expression. The numbers and the operators are separated by spaces.
Constraints:
All numbers in the expression are nonnegative and are less than or equal to 100.
The length of the expression is no more than 250.
The length of the verify input code is no more than 10000.
The operators would only be '+', '-' or '*'.
It is guaranteed the numbers won't exceed 109 during the whole calculation process.
Output contains 2 lines.
The first line contains the verify code.
The second line contains an integer, representing the result of the postfix expression.