Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2022 Grenoble France September 19 23 2022 Proceedings Part 4 Lnai 13716

Authors: Massih-Reza Amini ,Stephane Canu ,Asja Fischer ,Tias Guns ,Petra Kralj Novak ,Grigorios Tsoumakas

1st Edition

3031264118, 978-3031264115

More Books

Students also viewed these Databases questions

Question

Where those not participating, encouraged to participate?

Answered: 1 week ago

Question

Were all members comfortable brainstorming in front of each other?

Answered: 1 week ago

Question

4. What will the team agreement contain?

Answered: 1 week ago