You want a program that can identify positive and negative numbers and then display the words "positive" or "negative" accordingly. Your program must also deal with zero separately, displaying the word "zero" if it is entered. After displaying the appropriate word, the program should skip a line and display the words "To try another number, run this program again.".
The analysis and documentation for this problem appears below followed by the C++ source code.
The following documentation is intended to serve as an example of what would be expected from an analyst when designing a program related to the situation described above. All emphasized text below serves only to clarify the documentation for students, but would not actually appear in the real documentation.
Request and store a number and then display a word indicating its sign. If the number is positive, display the word "positive". If it is negative, display the word "negative". If it is zero, display the word "zero". After displaying the appropriate word, the program should skip a line and display the words "To try another number, run this program again.".
Programs that involve selection of alternative actions will always have more than one (and often many) possible results. The output produced by a program can differ drastically depending on the decisions it makes. Because of this, samples of the results expected from each decision must be demonstrated separately by providing multiple sample outputs; one for every possible path through the flowchart. These sets of possible program reactions are sometimes referred to as "scenarios". Program designers are required to determine multiple sets of sample input data that will result in each path being demonstrated, and then document each of these in separate samples for each scenario as shown below.
Note: The first two lines are the "Introduction". Bracketed items indicate user input.
1 |
Sign Notification Program |
1 |
Sign Notification Program |
1 |
Sign Notification Program |
| IDENTIFIER | DESCRIPTION | DATA TYPE | SOURCE | USAGE | DEST. |
|---|---|---|---|---|---|
| N | Number to be analyzed | Integer | Keyboard | Tested | --- |
A flowchart is a graphic algorithm that helps to illustrate the flow of control of a program as the processor would advance from one step to another, often in simple sequential order, but sometimes following more complex structures. In this case the processor must use its ability to compare and recognize relationships between data such as greater, less than, or equal to, and make a decision about which step(s) to process next. As long as the order of execution of steps continues to proceed toward the end of the program without branching backwards to a previous step, then the structure being followed is known as selection. For more information about what each shape below represents, view the web page about Flowcharting Symbols & Guidelines.

(The outline below would be redundant if a flowchart is provided, but is added in this example to show an optional algorithm format)
a. Start
b. Display the Introduction (see Sample Softcopy).
b1. Display "Sign Notification Program" message and return.
b2. Display a blank line.
c. Request and store N
c1. Prompt on screen with "Enter a number to analyze: ".
c2. Store keyed-in response in N.
d. If N is zero:
then: display "That number is zero." message and return
otherwise:
If N is greater than zero:
then: display "That is a positive number." message and return
otherwise: display "That is a negative number." message and return.
e. Display a blank line.
f. Display the words "To try another number, run this program again."
g. End
A program that involves selection of alternative branches will always have more than one (and often many) possible paths through its flowchart (algorithm). Because of this, each of these paths must be tested separately by performing one test for every possible path through the flowchart. Program designers have to define different sets of test input data to ensure that each scenario is tested, and must document each of these tests separately (as shown below).
Desk Check Tracing Charts for programs that select alternative branches based on test conditions must include columns to trace the true/false results of those conditions. One column should be added for each diamond shaped symbol in the flowchart using the condition as the column heading. The example above involves two tests, so two extra columns will be added to the Tracing Chart along with the one column necessary to trace the value of variable N.
| N | N = 0 | N > 0 |
|---|---|---|
| 0 | ||
| True |
1 |
Sign Notification Program |
Separate pairs of documents (Tracing Chart and Test Output) would be provided to prove that the flowchart worked for each scenario.
Another (but not as common) Desk Check documentation technique can be used that blends together the Tracing Chart and the Test Output for each scenario into one document. This alternative way of documenting your desk check activity is illustrated below for the other two scenarios defined in the original Sample Softcopies.
| N | N = 0 | N > 0 | |
|---|---|---|---|
Sign Notification Program |
|||
| 5 | |||
| False | |||
| True | |||
That is a positive number. |
|||
| N | N = 0 | N > 0 | |
|---|---|---|---|
Sign Notification Program |
|||
| -2 | |||
| False | |||
| False | |||
That is a negative number. |
|||
/* sign.cpp - an example of the selection structure */
/* Written by: Randolph Gibson - Date: Sept. 11, 2011 */
#include <iostream>
using namespace std;
int N; /* A number to be evaluated */
int main ()
{
cout << "Sign Notification Program\n\n";
cout << "Enter a number to analyze: ";
cin >> N;
if (N == 0) cout << "That number is zero.\n";
else if (N > 0) cout << "That is a positive number.\n";
else cout << "That is a negative number.\n";
cout << "\nTo try another number, run this program again.\n";
return 0; /* Return zero error code to parent process */
}