Defining Diagram Guide


Home

The defining diagram provides a high level outline of the algorithm and data used. For most problems it isn't feasible or wise to leap straight into pseudo code or program code - defining diagrams allow the programmer to broadly specify what is to be done without getting immersed in too much detail. Keeping complexity to a minimum is essential if larger problems are to be successfully tackled.

We will be using Defining Diagrams to provide and give an overview of the problem. Defining Diagrams are used to broadly state what is to be done (processing), what data needs to be supplied to solve the problem (inputs) and the results (outputs).

A Defining Diagram has 3 columns and 2 rows. The columns are, in order: Input, Processing and Output. The first row has the column headings: "Input", "Processing" and "Output", and the second row the data and actions as appropriate.

The processing section is used to specify the main actions. Details such as selection and repetition are usually omitted.

Example 1

Input two numbers, add the two numbers together and display their total.

Example Program Run

Run
Number 1 ? 10
Number 2 ? 3
Total = 13

Steps in Developing Defining Diagrams

Study the problem identifying the inputs, processing and outputs.

Inputs and outputs are usually the things being acted on and are usually referred to by descriptive words e.g. two numbers, total

e.g. Input two numbers, add the two numbers together and display their total.

The processing required is usually indicated by verbs - indicating the actions to be performed e.g. input, add, display

e.g. Input two numbers, add the two numbers together and display their total.

Step 2a:  Determine the outputs (result) required:

It is often easiest to identify the output(s) for a problem. In this case the user wants to know what the total of the two numbers is.

Step 2b: What processing is required to get to obtain the result:

The two numbers must be input, added together and the total displayed.

Step 2c: What inputs are needed:

What is the least amount of information that must be supplied by the user. If the information can be provided by another source (e.g. calculation) then don't ask the user. The two numbers to be added can only be obtained from the user, there is no other way to get them.

The inputs are number1 and number2 (or other suitable names)

Step 2d: Develop the Defining Diagram

Inputs Processing Outputs
number1, number2 Input number1, number2
Add the numbers together
Display the total
total

Example 2

Read two numbers from a file, add the two numbers together and write their total to a file.

The only changes from the above example are in the Processing section.

Step 2d: Develop the Defining Diagram

A common question is: Why do we need to restate that values are Input in the processing section when the variables are already specified as inputs in the Inputs section. Including something in the Inputs section indicates that this data needs to be supplied from an external source (e.g. a user or a file) to solve the problem, whereas the action "Input number1, number2" refers to the way that the variables number1 and number2 are obtained (they are input by the user). In the following example number1 and number2 are read from a file and the result written to a file. Note that there are no changes to the sections Inputs and Outputs, the same data are required. The only changes required are to the processing section.

Note: We won't be using data files in this subject.

Inputs Processing Outputs
number1, number2 Read number1, number2 from file numbers.dat
Add the numbers together
Write their total to the file results.dat
total

Example 3

A club requires a program to calculate the cost of membership. The cost of membership depends on the membership type. Full members ("F") are charged $160 per year, Juniors ("J") are charged $80 per year, and Life members ("L") are charged $10 per year. Assume that only valid membership types ("F", "K" or "L") are input.

Example Runs

Run
Membership type (F = Full, J = Junior, L = Life) ? F
Annual Membership = $160
Run
Membership type (F = Full, J = Junior, L = Life) ? J
Annual Membership = $80
Run
Membership type (F = Full, J = Junior, L = Life) ? L
Annual Membership = $10

Defining Diagram

Inputs Processing Output
membershipType Input membershipType
Determine membershipCost
Display membershipCost
membershipCost

Discussion

This problem requires selection. This is not mentioned in the defining diagram as the only the main tasks to be performed are specified, not control information such as selection and repetition.

Example 4

Problem Description

The user is to input prices of items for sale. At the end of the day the total of the sales made, the number of items sold and the average price of items sold is to be displayed.

Example Run

Run
Price (0 to exit) ($) ? 10
Price (0 to exit) ($) ? 110
Price (0 to exit) ($) ? 30
Price (0 to exit) ($) ? 0

Number of items sold = 3
Total = $150.00
Average price = $50.00

Defining Diagram

Inputs Processing Output
price Input prices
Sum the prices
Count the items
Calculate the average price
Display totalPrice, count, average
totalPrice
count
average

Discussion

This problem requires repetition. This is not mentioned in the defining diagram as the only the main tasks to be performed are specified, not control information such as selection and repetition.

Further Reading


Written by Tim Whitfort.