Program Class
The model for the rpn calculator: creates a push-pop stack object to hold and process digits and operators.
Constructor
Program
()
Void
Returns:
Void:
Methods
clear
()
Void
Clears the stack by setting its length to zero.
Returns:
Void:
parseStack
(
Float
-
stack
Recursive function to parse stack and perform all operations.
Parameters:
-
stack
Arraymust be a copy of this.stack
Returns:
Float:
performOperation
(
Float
-
o
Function called when an operator key (e.g. + or /) is pressed.
Parameters:
-
o
Objectmay be a Number or String
Returns:
Float:
pop
()
Mixed
Fetches the top item off the stack.
Returns:
Mixed:
Number | String
push
()
Void
Put an item onto the top of the stack.
Returns:
Void:
runProgram
()
Float
Calls parseStack, which calculates the stack.
Returns:
Float:
undo
()
Void
Removes the last-entered operand from the stack (pops and discards it).
Returns:
Void:
Properties
stack
Array
A stack to store the input values and functions.