For this project, you will read an infix expression, convert it to postfix, evaluate the postfix expression, and print out the answer. You will need to define and implement your own Stack class and a Calculator class. Your Stack class should support standard stack operations, which you can implement with either a linked list or an array. You should use a class template Stack in C++, but an integer Stack class would work as well since a character would be considered a subset of integers. Your Calculator class stores an infix operation and it provides the public operations below. Feel free to add private operations and data. The Calculator class should use a character stack to convert infix to postfix (storing operators) and then uses an integer stack to evaluate the expression (storing operands).

EBK JAVA PROGRAMMING
8th Edition
ISBN:9781305480537
Author:FARRELL
Publisher:FARRELL
Chapter2: Using Data
Section: Chapter Questions
Problem 12PE
icon
Related questions
Question

For this project, you will read an infix expression, convert it to postfix, evaluate the postfix expression, and print out the answer. You will need to define and implement your own Stack class and a Calculator class. Your Stack class should support standard stack operations, which you can implement with either a linked list or an array. You should use a class template Stack in C++, but an integer Stack class would work as well since a character would be considered a subset of integers. Your Calculator class stores an infix operation and it provides the public operations below. Feel free to add private operations and data. The Calculator class should use a character stack to convert infix to postfix (storing operators) and then uses an integer stack to evaluate the expression (storing operands).

C++ ( I WILL THUMBS DOWN IF YOU USE HJAVA)

Public operations in Calculator class:
A constructor that receives a valid expression as string like "5* 2^ 3"
postfix() - returns the postfix expression
eval() - returns the result of the expression
setExpr() - receives the infix expression as string and store it
getExpr() - returns the infix expression as string
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 expressions are valid and tokens are always separated by one space):
17/(2+3) - 13
5 2^3
2^3^2
10* (2+4) + 8 /2
7*(5+6)
Create and use a Calculator object to perform conversion and evaluation
Obtain and print out the postfix expression (examples above)
17 23+/13 -
523 A*
232 AA
10 24 +*82/+
756+*
Obtain and print out the answer of the evaluation (examples above)
-10
40
512
64
77
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). Run
the following 3 test cases plus 2* 3*4 as the minimum set of test cases.
Transcribed Image Text:Public operations in Calculator class: A constructor that receives a valid expression as string like "5* 2^ 3" postfix() - returns the postfix expression eval() - returns the result of the expression setExpr() - receives the infix expression as string and store it getExpr() - returns the infix expression as string 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 expressions are valid and tokens are always separated by one space): 17/(2+3) - 13 5 2^3 2^3^2 10* (2+4) + 8 /2 7*(5+6) Create and use a Calculator object to perform conversion and evaluation Obtain and print out the postfix expression (examples above) 17 23+/13 - 523 A* 232 AA 10 24 +*82/+ 756+* Obtain and print out the answer of the evaluation (examples above) -10 40 512 64 77 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). Run the following 3 test cases plus 2* 3*4 as the minimum set of test cases.
Sample input/output:
[Your name) Calculator Enter 0 to exit the program
Enter an expression: 17/ ( 2 + 3) - 13<E
Postfix expression: 17 2 3 + / 13
Result: -10
Enter an expression: 5 * 2 ^ 3<E>
Postfix expression: 5 2 3 ^ *
Result: 40
Enter an expression: 2 ^3^ 2<E>
Postfix expression: 2 32 ^^
Result: 512
Enter an expression: 0<E>
Thanks for using my calculator.
Transcribed Image Text:Sample input/output: [Your name) Calculator Enter 0 to exit the program Enter an expression: 17/ ( 2 + 3) - 13<E Postfix expression: 17 2 3 + / 13 Result: -10 Enter an expression: 5 * 2 ^ 3<E> Postfix expression: 5 2 3 ^ * Result: 40 Enter an expression: 2 ^3^ 2<E> Postfix expression: 2 32 ^^ Result: 512 Enter an expression: 0<E> Thanks for using my calculator.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Stack
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning