/*
------------------------------------------------------------------------
MEMORIAL UNIVERSITY OF NEWFOUNDLAND
Faculty of Engineering and Applied Science
Engineering 3891(Advanced Programming)
Assignment #5
Instructor: Michael Bruce-Lockhart
Date: 00.10.13 Due: 00.10.20.08:50
------------------------------------------------------------------------
*/
/* This is the interface for a four function myComplex number
calculator which uses Reverse Polish Notation. The
calculator keeps an internal stack of myComplex numbers. The
user may push numbers on the stack and pop them off again. A
calculation utilizes the top (most recently pushed) numbers
and replaces them with the result. No action is taken if the
operation is illegal (not enough nos. on the stack or divide
by zero). Mixed mode calculations are supported only
indirectly (i.e. all nos. must be myComplex but there's nothing
to say their real or imaginary parts can't be zero).
A stack is just like a queue EXCEPT that the first item
pushed onto the stack is the last item that can be popped
off. It's known as a First In Last Out (FILO) structure as
opposed to the First In First Out (FIFO) behaviour that
characterizes a queue.
It gets its name from one of those old spring-loaded plate
dispensers cafeterias used to have - the first plate put in
by the staff goes on the bottom, then, the next and so on so
that the first one put in is actually the last one removed
by the patrons.
Unlike last week's assignment, this stack is NOT circular (we
say its linear).
*/
// No of myComplex nos, that can be held - your stack MUST be this size
const int STACKSIZE = 10;
// Needed types
struct myComplex {
double re,im;
};
// functions
bool push(myComplex x);
/* push one number on the stack. Return true if
operation successful, false if the stack was full (in which
case x is NOT put on the stack - nothing is done with it at all).
*/
bool pop(myComplex& x);
/* pop a number from the stack and pass it back to the
referenced variable. Return true if successful, false if the
stack is empty. */
bool oper(char op);
/* Carries out requested operation: '*' for multiply, '/'
for divide, '+' for add, and '-' for subtract. Any other
character will result in no action and a return value of
false. Both operands are replaced on the stack with the
result. The value on the Top of the Stack is the right hand
operand and the next to Top of Stack is the left hand
operand. Thus the calling sequence
push(x);
push(y);
oper('-');
leaves x-y on top of the stack in place of x.(If x and y were
the only things pushed on the stack it will have only one item
in it after the subtraction - the result.)
true is returned if the operation was carried out successfully,
false otherwise (insufficient nos. on the stack, divide by zero, etc.)
*/