C++:
Learning Outcomes
Implement two stacks and use them to implement an infix to prefix expression convertor
Stacks
A stack is an abstract data type which uses a sequential container and limits access to that container to one end. You may enter or remove from the container, but only at one end. Using the Linked List data structure from your last homework assignment, implement a Stack of type string.
The Stack should only have one data member: the Linked List. It should implement the following methods:
Your linked list should support adding to the end of the list.
Infix to Prefix Conversion
Suppose you have an infix expression a+c^d/g-h. Using the math operation priority, we learned this is equal to a+(((c^d)/g)-h).
The prefix expression of the above infix one is: + a - / ^ c d g h
Your program must read a math expression in string and prints its prefix equivalent.
An example of program run:
Please enter the infix math Expression: a+c^d/g-h
The equivalent prefix math expression is : + a - / ^ c d g h
Do you want to add another expression [Y/N]: Y
Another example of the program in which program returns an error message.
Please enter the infix math Expression: a++c^d/g-h
Sorry! The expression is not valid.
Do you want to add another expression [Y/N]: Y
The user must use * to declare the multiplication, and ^ to declare power.
The only valid operators are: ^ * / + -
User may enter ( and ) as many as they want provided the expression is correct. For example, the following expression is valid:
(((((((a+b)))))))+((((c))))
And the output must be: + + a b c
Program must treat variables such as ab as one operand and not the multiplication of a and b. (ab!=a*b)
See following example:
Please enter the infix math Expression: aa+c^dsa/gl-h
The equivalent prefix math expression is : + aa - / ^ c dsa g h
The aa and dsa are two operands.
Rules for Implementation
Start at the beginning of the expression string and evaluate each character based on these rules.
a+b*c the b and c are the operands of the * operator. Then * b c all together is an operand to the + operator (the other operand of this operator is a)
After all characters have been evaluated, perform one last check:
The InfixToPrefix Class
Create a new class called InfixToPrefix.hpp containing the following fields.
It will also have the following constructors and methods.
Write the Driver.
The program will begin with a single prompt: " Please enter the infix math Expression: "
The user will supply an expression. Next, the program will prints the prefix expression of the given expression. If the expression is not valid, report print that the expression is not a valid infix expression. Finally, the program will wait for a final keystroke (i.e. pause). Make sure that your program works for all of the sample expressions.
What to Hand In
C++: Learning Outcomes Implement two stacks and use them to implement an infix to prefix expression...
Programming Assignment 2 – RPN Calculator – Infix to Postfix Conversion and The Evaluations of the Postfix Expression. You are to design and implement and algorithm in Java, to input an Infix expression , convert to a postfix expression and finally evaluate the postfix expression… Follow the examples done during class lectures… We are used to infix notation - ”3 + 4” - where the operator is between the operands. There is also prefix notation, where the operand comes before...
You are to write a program name expressionTree.java that evaluates an infix expression entered by the user. The expression may contain the following tokens: (1) Integer constants (a series of decimal digits). (2) One alphabetic character - "x" (representing a value to be supplied later). (3) Binary operators (+, -, *, / and % (modulo)). (4) Parentheses You will parse the input expression creating an expression tree with the tokens, then use the postOrder tree traversal algorithm to extract...
Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...
Infix Expression Evaluator For this project, write a C program that will evaluate an infix expression. The algorithm REQUIRED for this program will use two stacks, an operator stack and a value stack. Both stacks MUST be implemented using a linked list. For this program, you are to write functions for the linked list stacks with the following names: int isEmpty (stack); void push (stack, data); data top (stack); void pop (stack); // return TRUE if the stack has no...
JAVA, please You must write a robust program meaning that your program should not crash with any given data. Data validation must be done any time that user enters an input. Write a program that 1. Gets an infix expression form the user and evaluate the expression using stack ADT a. Finds the postfix equivalent of the given infix expression b. Evaluate the created postfix expression. c. Note: your program should not crash when you enter an invalid expression such...
I NEED SAMPLE PRINT OUT AS WELL AS CODE PLEASE!!!! Objectives: To gain experience with stacks. Documentation: Explain the purpose of the program as detail as possible - 8%. Develop a solution for the problem and mention algorithms to be used -12% List data structures to be used in solution. - 5%. Give a description of how to use the program and expected input/output - 5% Explain the purpose of each class you develop in the program. - 5%. Programming:...
EVALUATING GENERAL INFIX EXPRESSIONS INTRODUCTION The notation in which we usually write arithmetic expressions is called infix notation; in it, operators are written between their operands: X + Y. Such expressions can be ambiguous; do we add or multiply first in the expression 5 + 3 * 2? Parentheses and rules of precedence and association clarify such ambiguities: multiplication and division take precedence over addition and subtraction, and operators associate from left to right. This project implements and exercises a stack-based algorithm that evaluates...
We as humans write math expression in infix notation, e.g. 5 + 2 (the operators are written in-between the operands). In a computer’s language, however, it is preferred to have the operators on the right side of the operands, i.e. 5 2 +. For more complex expressions that include parenthesis and multiple operators, a compiler has to convert the expression into postfix first and then evaluate the resulting postfix. Write a program that takes an “infix” expression as input, uses...
implement a class of infix calculators (Using C++). Consider a simple infix expression that consist of single digit operands; the operators +, -, *, and / ; and parentheses. Assume that unary operators are illegal and that the expression contains no embedded spaces. Design and implement a class of infix calculators. Use the algorithms given in the chapter 6 to evaluate infix expressions as entered into the calculator. You must first convert the infix expression to postfix form and then...
Using Java- Write a program that takes an arithmetic expression in an infix form, converts it to a postfix form and then evaluates it. Use linked lists for the infix and postfix queues and the operator and value stacks. You must use sperate Stack and Queue classes with a driver class to run the program. example Input : 111++ Output : (1+ (1+ 1)) Answer: 3