You are on page 1of 8

Software Requirements Document

A Multi-Function Calculator

1 Scope

This document specifies the functional requirements for a multi-function calculator


program. The program is designed to act like a “handheld calculator ” with the usual
standard functions (add, subtract, multiply, divide, exponentiation, and memory).
Additionally, the calculator will have the additional capability of performing functions in
binary (base 2), octal (base 8) and hexadecimal (base 16), in addition to the usual decimal
(base 10). The program is designed to be as easy to use as a regular calculator.

2 Environment and Interface Requirements

This section describes the external influences imposed on the calculator program.

2.1 Hardware and Software

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.

2.2 External Data Bases and File Interfaces

There are no existing external data bases or files that will be needed by this program.

2.3 Human Interfaces

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.

3.1 Data Flow Diagram

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.

Figure 1: Data Flow diagram for the calculator program

3.2 Major Function Descriptions

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:

where , and are entities that are


defined below, and the brackets indicate optional items. Blanks shall be allowed
around any of the items. Thus, both of the forms shown below are legal and
equivalent:
2. A has the form:

or, simply

where:

a string of ’s and ’s for a binary number


a string of digits for a decimal
number
a string of digits for a hexadecimal
number (the decimal point)
or for binary
or or none for
decimal or for
hexadecimal
memory recall function, described later
3. An is one of:
for addition
for subtraction
for multiplication
for division
for exponentiation
4. If an illegal sequence is detected, an error message is to be printed, along with an indi-
cation of where within the input the error was detected. A form similar to that shown
earlier should be used.

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:

1. Exponentiation can be restricted to whole-number powers. If a number with a


fractional part is input as an exponent, the program should use the nearest whole
number power (i.e., rounded), and then print a message to inform the user of the
variation.
2. Division by zero should be detected by the program, and an error message should be
printed.
3. Overflow and underflow do NOT need to be detected.
4. The order of calculation need only proceed from left to right; it is not necessary (or rec-
ommended!) that any hierarchy be placed on the order of calculations.

3.2.3 Memory Operations

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:

1. Whenever the equals sign ( ) is input.


2. Whenever is input (the contents of memory is displayed)
3. Optionally, whenever the key is pressed.

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.

3. The source language to be used is standard C++. Any non-standard or system-


dependent features shall be avoided if at all possible.

You might also like