Line 128 The names
of
the five days
of
the week are displayed in column heading
form.
Lines 138 - 148 The values
of
the five medians stored in the array M are printed.
M(l)
contains the median for Monday,
M(2)
the median for
Tuesday,etc.
Line 158 The END statement terminates execution
of
the program. Without the END
statement, execution would continue with lines
500 - 570.
If
that were to happen, the
RETURN statement in line
570 would generate an error message because there was no
corresponding GOSUB statement. The STOP statement could have been used instead
of
the END statement.
Lines 588 • 578 This is the subroutine which sorts the array S and compute,s the
median. Before this subroutine can be used (or
"called"),
the variable S must have
the appropriate values assigned to it. Upon returning from the subroutine, the median
is stored in the variable MD.
The subroutine can be called
as
many times as necessary in a program
as
long as the
input variables
(N
and
S)
are initialized before it is called. When the RETURN
statement is executed, control jumps to the statement immediately following the
GOSUB statement.
Here are some rules governing the use
of
subroutines.
1)
Every subroutine must contain a
RETURN
statement. It may contain more
than one RETURN statement,
ifthere are several places in the subroutine
from which you
want
to
return.
2)
A program may contain several subroutines.
3)
A subroutine may call another subroutine.
4) A subroutine may be placed anywhere in a program, as long as it
is
executed
only from a
GOSUB call.
Subroutines are very useful in programming. They allow you to avoid repetitive blocks
of
code. They also allow you
to
write your program in modules or blocks so that it is
easier to write and to understand. The program in this experiment was simplified by
putting the sorting and median calculation in a subroutine.
What you have learned:
In this lesson you have seen how arrays, both one and two dimensional, can be used
to
store data, so that certain information can be extracted. The TAB statement was
used with the PRINT statement
to
space the output. Two types
of
averages were
calculated, the mean and the median. To calculate the median it was necessary
to
sort
the data. The INT function was useful in simplifying the calculation
of
the median.
Finally, subroutines can often be used to make your program easier to write and more
readily understandable.
143