Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit


Assignment 3


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.

■ (optional) anything special about your submission that the TA should take note of.

● 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


Academic Honesty:

All students should follow Student Academic Honesty Code (http://watson.binghamton.edu/acadhonorcode.html). All forms of cheating will be treated with utmost seriousness. You may discuss the problems with other students, however, you must write your OWN codes and solutions. Discussing solutions to the problem is NOT acceptable. Copying an assignment from another student or allowing another student to copy your work may lead to an automatic F for this course. If you borrow small parts of code/text from Internet, you must acknowledge this in your submission. Also, you must clearly understand and be able to explain the material. Copying entire material or large parts of such material from the Internet will be considered academic dishonesty. Moss will be used to detect plagiarism in programming assignments. You need ensure that your code and documentation are protected and not accessible to other students. Use chmod 700 command to change the permissions of your working directories before you start working on the assignments. If you have any questions about whether an act of collaboration may be treated as academic dishonesty, please consult the instructor before you collaborate.