100% Guaranteed Results


CS571 – Assignment 3 Solved
$ 24.99
Category:

Description

5/5 – (1 vote)

This assignment is done individually or by a group of 2 students (each group submits only ONE copy of the assignment)
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

2. The user clicks “on”
The calculator displays 0

2. 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

3. 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

4. The user clicks “off” and “1”
The calculator erases the display and displays nothing when the user clicks “1”

5. 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

6. 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

Submission guideline
• Please hand in your source code electronically. The file name should be calc.html.
• Write a README file (text file, do not submit a .doc file) which contains  Name and email address of group members.
• Place calc.html and README under one directory with a unique name (such as p3-[userid] for assignment 3, e.g. p3-pyang).
• Tar the contents of this directory using the following command.
tar –cvf [directory_name].tar [directory_name]
E.g. tar -cvf p3-pyang.tar p3-pyang/
• Use brightspace.binghamton.edu to upload the tared file you created above.
Grading guideline
Readme, correct file names: 4’ Correctness: 96

Reviews

There are no reviews yet.

Be the first to review “CS571 – Assignment 3 Solved”

Your email address will not be published. Required fields are marked *

Related products