Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSC 220 Data Structures Program 45 (follows: L6 - infix and Postfix) Description: Your objective is to take an infix expression from the user, convert

image text in transcribed
image text in transcribed
CSC 220 Data Structures Program 45 (follows: L6 - infix and Postfix) Description: Your objective is to take an infix expression from the user, convert it into postfix form, then evaluate it to find an answer to the expression. You will need your generic Stack, generic Queue, generic List and generic Node class for this assignment. The reason why you will need generic classes, is that in some cases you will need to use a stack of Character objects and in other cases you will need a stack of integer objects. Create a file called "Main.java" that would contain a public class called "Main". All work will be done inside this Main class. Here are the methods you must implement inside this class: - Entry point: This should prompt the user for an infix expression, send that expression to the Infixtopostfix method (described below), this will return a postix expression (as a string), you will then send that to evalpostfix (described below) for evaluation, and then finally print out the summary shown in the sample output. int getinfixpriority (char c) This takes in a char (a single character) and determines the infix priority as described in the notes. it then returns this priority. - int getstackPriority (char c) This takes in a char (a single character) and determines the stack priority as described in the notes. It then returns this priority. boolean isoperand (char c) This will return true if c is an operand (basically a single digit from 0 to 9 inclusively). it will return false otherwise. To keep things simple, only single digit numbers are allowed in the input specified by the user. This means both the infix and the postfix notation will contain only single digit numbers. As you evaluate the expression, mulb-digit numbers will naturally arise, and that's ok. int eval (char operator, int a, int b) The operator character is one of the following operators t, ,%,1, or . These are the only operators allowed (except for parentheses which is not handled by this method). 5 imply return a value of 1 if the operator is invalid. a and b are your operands. The order goes, a operator b. This method returns the result of applying the given operator, oper at or, to the operands, a and b - String infixtopostfix (String infixstring) o. This method takes in an expression in infix form and produces the equivalent expression in postfix form. Here is where your stack and queve implementations will come into play. You must implement the algorithm from the notes. I don't want you grabbing some code from some online source and sticking it in here. - int evalpostfix (string postfixstring) o This takes an expression in postfix form and evaluates it, returning the evaluated result. All numbers are restricted to a single digit, no floating point numbers allowed, division symbols are handled as integer division, the final answer along with any intermediate answers are allowed to be multiple digits (i.e. it should return the mathematically correct answer, using integer division for any division). No input validation is needed here. Assume the user will only enter single digit numbers and no floats. Also assume the user will only enter valid operators along with parentheses (if desired). No spaces are allowed in the input (this is so parsing the input is made a little easier), so you can safely assume no spaces are in the input. The valid operators you must handle are: + (addition), - (subtraction), / (integer division), (multiplication), and ^ (exponentiation)

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

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

Address an envelope properly.

Answered: 1 week ago

Question

Discuss guidelines for ethical business communication.

Answered: 1 week ago