Question: MUST CREATE TWO CLASS BOTH CALCULATOR AND STACK CLASS Write a program in c++ that reads an infix expression, converts it to a postfix expression,

MUST CREATE TWO CLASS BOTH CALCULATOR AND STACK CLASS

Write a program in c++ that reads an infix expression, converts it to a postfix expression, evaluates the postfix expression, and prints out the answer. You must define and implement your own Stack class and a Calculator class (feel free to add additional classes). Your Stack class supports standard basic stack operations and you can implement it with an array or a linked list. You should create a class template Stack in C++ . Your Calculator class stores an infix expression and it should provide operations to return an equivalent postfix expression as well as an integer result of the expression. The Calculator class uses a character stack to convert infix expression to postfix expression (storing operators) and then uses an integer stack to evaluate the postfix expression (storing operands). Your application (main) should perform the following: Ask the user to input an infix expression. Examples of an infix expressions might be (you may assume that tokens are always separated by one space): 17 / ( 2 + 3 ) - 13 5 * 2 ^ 3 Create and use a Calculator object to perform conversion and evaluation Obtain and print out the postfix expression (examples above) 17 2 3 + / 13 - 5 2 3 ^ * Obtain and print out the answer of the evaluation (examples above) -10 40 Your program must be able to work with int operands and it must recognize binary operators +, - , *, / , %, and ^. In addition, it must recognize the parenthesis: ( ). You can assume that the user will input a valid infix expression. Your program will continue to process expressions until the user enters 0 as an expression (use a sentinel loop)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!