Professional Documents
Culture Documents
A Multi-Function Calculator
1 Scope
This section describes the external influences imposed on the calculator program.
The program shall be written in standard C++, as compiled by the GNU C++ compiler ( ).
The program shall use only standard C++ library functions. The program shall be usable on
any system which supports the compiler, and shall not require any particular hardware or
software.
There are no existing external data bases or files that will be needed by this program.
The program shall operate as much as possible in the same way as a regular handheld calcu-
lator, such that anyone familiar with the operation of such a device should have little trouble
using the program. Once the program is started, the program shall produce a prompt ( ).
The user can then type a sequence of numbers and operators, similar to a regular calculator.
The program will display the calculated answer to the entered problem on the line
following the input line. Some examples that show the proper function of the calculator
follow below (the computer-generated output is underlined):
1
If an unintelligible sequence of characters or operators is entered, an error message shall be
produced that indicates where the problem was first detected:
In addition to decimal (base 10) numbers, the calculator shall be able to handle numbers en-
tered in binary, octal, or hexadecimal. The base of the number shall be indicated by
appending one of the following letters to the numeric value:
or - binary
or - octal
or or none -
decimal or -
hexadecimal
One of these letters can also be input following the equals (‘=’) sign; the letter shall indicate
the base to use for outputting the result. Whenever a base other than decimal is used for
output, one of the above letters shall also be appended to the value that is displayed. Some
examples follow:
In this example, the first number is binary, the second is hexadeciaml, while the result is deci-
mal.
This is the same problem as above, except that the result is output in hexadecimal.
A complete description of all the legal input commands is given in section 3, which follows.
3 Functions
The following section outlines all of the functions required of the calculator program.
Figure 1 is a data flow diagram which identifies the major functions required of the
calculator program and shows their relationship to each other. The numbers included with
each function are keyed to the subsections below that describe that function.
The major functions identified in the data flow diagram of figure 1 are now described in
detail.
3.2.1 Input
The input function shall accept input from the user via the terminal, validate that input, and
then send that input to the calculate function. All user interaction with the program will
occur through this function. The following details apply:
1. The input from the user shall look like “standard calculator input,” having the general
form:
or, simply
where:
5. To end the calculator program, the user shall type a (or ) on the input line. When this
occurs, control shall be returned to the operating system.
3.2.2 Calculate
This function will accept correct input from the input function and will perform the
arithmetic operations requested by the input. The five arithmetic functions are listed above.
The follow- ing specifications apply:
This function will provide the “standard calculator ” single memory operations, including:
Memory Clear
Add the result of the last computation to the present contents of memory
Subtract the result of the last computation to the present contents of memory
Recall the current contents of the memory for use in a calculation
Display (print) the current value of memory on the screen.
3.2.4 Output
This function will display the results of a calculation or memory. Results should be
displayed under the following conditions:
Results shall be displayed in base 10, if no base indicator is typed after the equals sign, or
in the base specified by the base indicator typed following the equals sign. The output shall
follow these rules:
1. The number output should include all of the digits required to represent the whole
num- ber portion of the number.
2. For all bases, if there is no fractional part in the result, no decimal point or digits
follow- ing the decimal point should be displayed.
3. For binary numbers, if there is a fractional part, then the decimal point and 10 (ten)
binary digits shall be displayed in the fraction.
4. For octal and decimal numbers, if there is a fractional part, then the decimal point and
5 digits shall be displayed in the fraction.
5. For hexadecimal numbers, if there is a fractional part, then the decimal point and 4
digits shall be displayed in the fraction.
6. For output of numbers other than base ten, the base indicator should also be output.
7. A line containing only the equals sign and possibly a base indicator should cause the
previous result to be re-output in the specified base.
4 General Design Guidelines
The following are general guidelines associated with the calculator program:
1. The program should be “bomb-proof.” With the exception of overflow and underflow,
no user input should cause the program to terminate abnormally.
2. This specification details minimum requirements for the program. As long as these re-
quirements are met, any additional features or functions, or other operational
enhance- ments, may be added.