Question
use link based stack and make separate header, implementation and main driver file Consider simple infix expressions that consist of single-digit operands; the operators +,
use link based stack and make separate header, implementation and main driver file
Consider simple infix expressions that consist of single-digit operands; the operators +, -, *, and /; and the parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces.
Design and implement a class of infix calculators. The class should have the following members: Private members: 1. a string to store an infix expression for evaluation. 2. a private member function that checks if an infix expression is well formed. 3. a private member function that checks for balanced brackets of an expression using the algorithm studied in Chapter 6. 4. a private member function that converts an infix expression to a postfix expression using the algorithm studied in Chapter 6. 5. a private member function that determines the precedence of an operator 6. a private member function that evaluates a postfix expression using the algorithm studied in Chapter 6.
Public members: 1. a default constructor. 2. a function that sets the data member by an infix expression. The function must first check if the infix expression is well formed and balanced with brackets by calling private member function 2 and 3 before passing it to the data member. The function returns true if the operation is successfully performed. Otherwise it returns false to indicate the parameter expression is not valid. 3. a function that evaluates the expression stored in the data member. This function should not have any parameters. The function should first convert the infix expression to its postfix form and then evaluate the resulting postfix expression.
Other requirements Use the link-based Stack with exceptions. Write a main function to test your calculators. Your program should allow the user to evaluate additional expressions until the user wants to end the program. You should not assume that the expression is well-formed. The user is asked to reenter an expression if the expression entered is not well formed. You should not assume that the parentheses in the expression are balanced. The user is asked to reenter an expression if the expression entered is not balanced
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started