Display the converted expression

Assignment Help Basic Computer Science
Reference no: EM13306416

You are to write a program name calculator.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) x (representing a value to be supplied later).
(3) Unary operators (+ and -).
(4) Binary operators (+, -, *, / and %).
(5) Parentheses
Spaces between tokens are allowed but not required. The program will convert the expression to postfix (RPN) form and display the converted expression. In the postfix version of the expression, unary + will be removed, and the unary - operator will be replaced by the _ (underscore) character. The program will repeatedly prompt the user for the value of x, displaying the result from evaluating the expression each time. When the user enters the letter q instead of a number, the program terminates.

The following example illustrates the behavior of the program (user input is in bold and red):
Porgram output is in bold and green.

Enter infix expression: (x + 1) * (x - 2) / -4
Converted expression: x 1 + x 2 - * 4 _ /

Enter value of x: 5
Answer to expression: -4

Enter value of x: 7
Answer to expression: -10

Enter value of x: q

If the infix expression contains an error of any kind, the program must display the message Error in expression (with an optional explanation) and then terminate. The following examples illustrate various types of errors:

Enter infix expression: 1 2 +
Error in expression!! No operator between operands. Also last token must be an operand.

Enter infix expression: 10.4
Error in expression!! Cannot accept floating point numbers.

Enter infix expression: 1 ( + 2)
Error in expression!! No operator between operand and left parentheses.

Enter infix expression: 5 - (x - 2))
Error in expression!! No matching left parentheses for a right parentheses.

Enter infix expression: 1 ** 2
Error in expression!! The * operator cannot be preceded by a * operator.

The output of your program must match the format illustrated in this example.

Here are some other additional requirements for this program:

(1) You must use stack objects during the translation from infix to postfix and during the evaluation of the postfix expression.

(2) Operators must have the correct precedence and associativity. Unary operators take precedence over *, % and /, which in turn take precedence over binary + and -. Unary operators are right associative; binary operators are left associative.

Reference no: EM13306416

Questions Cloud

How to sketch the hgl and the egl for the system : What power must the pump supply to the system to pump the oil from the lower reservoir to the upper reservoir at a rate of .2 m^3/s. Sketch the HGL and the EGL for the system.
Use a recursive function, instead of nested for loops : Write a C program that will prompt the user to enter an integer and then it will print on the screen all the binary numbers of length n, where n is the integer variable inserted by the user.
Practice using recursion with data structures : Write a recursive method in this class called hasSameStructureAs(BinaryTree tree) that returns whether or not a tree has the same structure as another tree.
Citing legal sources : Citing Legal Sources
Display the converted expression : Spaces between tokens are allowed but not required. The program will convert the expression to postfix (RPN) form and display the converted expression.
What are the angles for the first three dark fringes : A student sets up a double slit interference experiment using light of wavelength λ. The separation between the slits is 25λ. What are the angles for the first three dark fringes
Compute the spontaneous emission wavelength : Consider an optical gain medium that has two levels at E 1=1.50 eV and E 2=3.50 eV. What is the spontaneous emission wavelength
Write a recursive method that returns the total number : Write a recursive method that returns the total number of handshakes that took place in a room with n people.
How much water does the irrigator need to apply : An irrigator uses the (old-fashioned) concept of plant available water to determine the irrigation water quantity needed to irrigate a 10 ha field, How much water does the irrigator need to apply

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Explain the concept of supply chain management

Explain the concept of supply chain management. Although R/Way offers services rather than products, could that concept apply to the design of R/Way's new system? If so, how?

  Drawing crow-s foot erd using a specialization hierarchy

Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if appropriate.

  What operations can you perform on pointers

How would you initialize a pointer that you do not want to point to anything? What is a null pointer and how do you create it?

  Determine features of ram to include in web server

Determine the features and capacities (RAM, disk storage, processor speed) that Amy should include in the Web server computer that she will need for her site.

  Example of weighted directed grap with weight function

Provide an example of weighted directed graph G = (V, E) with weight function ω:E→R and source vertex s such that G satisfies following property.

  Benefits of a web-based computing environment

Web-based computing so for this essay question, explain in scholarly detail benefits of a Web-based computing environment.

  How long will it take for input size

How long will it take for input size 500 if the running time is the following

  Fork function

Create a C program that takes an integer argument from the command line and outputs sum of all digits of the integer. For example, the result of the invocation sum of digits 12345 should be fifteen.

  Create an html5 document that contains an unordered list

Create an HTML5 document that contains an unordered list with links to the following examples headings, email, images as hyperlink these are from textbook, special characters, tables, HTML5 forms, and internal links to be included

  Construct resolution proofs to demonstrate truth

Can you construct resolution proofs to demonstrate the truth of each of these statements given the 5 facts listed above? Do so if possible.Otherwise add the facts you need & then construct the proofs.

  Write a program to print duplicates in a string and count

1. write a program to print duplicates in a string and their count.

  Compare and contrast the binary search trees

Compare and contrast the Binary Search Trees (BST) featuring the balancing operation implemented with the AVL trees.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd