[previous_group] [previous] [up] * [next_group]

The Specification - A Simple Calculator

In this program we will be implementing a calculator which accepts positive integer operands and operators as input forming an expression which is then evaluated and the results displayed. The calculator uses a "fancy" display to show input and results in a larger-than-normal size (try the executable provided to see what I mean).

The operators supported by the calculator are:


	+	for addition
	-	for subtraction
	x	for multiplication (note this is not *)
	/	for division
	=	for evaluation

In this calculator, there are NO precedence rules. Operators are evaluated from left to right as they are entered. When the evaluate operator ('=') is entered, the result of the expression is to be displayed, and no further input is accepted until an newline is entered. This newline clears the calculator display making it ready to accept the next expression.

Operands for this calculator may be arbitrary positive integers which may be entered in one of two forms, but MUST ALWAYS be followed by a single space character (this makes implementation easier). You will note that the display shows a small '@' character to indicate when the required space following an operand has been entered. Other than the newline at the end of an expression, all other white space characters entered are ignored by the calculator and not displayed. The forms of operands are:

Expressions are entered as an operand followed by an operator. For the arithmetic operators ('+', '-', 'x', and '/'), another operand is expected to follow. As described above, when the evaluate operator ('=') is entered, the result is displayed until a newline is entered.

One additional expression can be entered; namely, a 'q' character entered as the first character after the calculator prompt. This expression terminates the calculator.


Where do we begin?


Examples of Calculator Operations

[next_group]