[Solved] CS571 Assignment 3

$25

File Name: CS571_Assignment_3.zip
File Size: 169.56 KB

SKU: [Solved] CS571 Assignment 3 Category: Tag:
5/5 - (1 vote)

In this assignment, you will implement a postfix calculator that computes the value of postfix expressions using Javascript and HTML. The interface of the calculator is given below. Your calculator should have the same layout, i.e.. the first line shows buttons on off 0 1, the 2nd line shows buttons 2 3 4 5, etc.

Your calculator needs to handle only single-digit integers in the postfix expression. For example, 12+ represents 1+2 and 123+- represents 1-(2+3). There will be no space between single-digit integers.

Initially, the calculator is off. When the calculator is off, the calculator does not display anything until the user clicks the on button.

When the user clicks the on button, the calculator displays 0. When the user clicks the off button, the calculator erases the display.

If the calculator is on and the user clicks the button 0-9, +, -, *, or /, then the calculator displays the symbol on each button.

If the calculator is on and the user clicks clear, then the calculator displays 0.

If the calculator is on and the user clicks button =, then the calculator evaluates the expression entered by the user and displays the result.

You can assume that the arithmetic expression entered is always valid. For example, you do not need to consider invalid inputs such as 1+, 12+*, etc.

Hint: you can use a stack to implement the postfix calculator. Javascript provides function push to add an element to the stack and function pop to remove an element from the stack.

Examples

  1. The calculator is off and the user clicks 1

The calculator does not display anything

  1. The user clicks on

The calculator displays 0

  1. The calculator is on and the user clicks 1, 3, +, and =

The calculator displays 13+ before the user clicks =

After the user clicks =, the calculator displays 4

  1. The calculator is on and the user clicks clear, 1, 2, 3, +, -, and =

The calculator displays 0 when clear is clicked

The calculator then displays 123+- before = is clicked. After the user clicks =, the calculator displays -4

  1. The user clicks off and 1

The calculator erases the display and displays nothing when the user clicks 1

  1. The calculator is turned on and the user clicks 1, 3, +, =, clear, and 5

Before the user clicks =, the calculator displays 13+ After the user clicks =, the calculator displays 4

After the user clicks clear, the calculator displays 0

After the user clicks 5, the calculator displays 5

  1. The calculator is on and the user clicks 1, 3, +, =, 5, – and =

Before the user clicks =, the calculator displays 13+ After the user clicks =, the calculator displays 4

After the user clicks 5, the calculator displays 45

After the user clicks -, the calculator displays 45-

After the user clicks the 2nd =, the calculator displays -1

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS571 Assignment 3[Solved] CS571 Assignment 3
$25