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).

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education