After the program
is
entered, execute it. The output should appear
as:
MED
I
AN
SALES
MON
288.5
TUE
272.5
WED
325
THU
285
FRI
256.5
The median for each day of the week is printed below the name
of
the day. For each
day, the six sales values are sorted and the median computed
by
averaging the two
middle values.
Line 5 The OPEN statement allows the data to be read from a RAM file.
Line
Ht
The numeric variable N
is
assigned the value 6, indicating six weeks
of
data
for each day
of
the week.
Lines 28 - 48 The data
is
read from RAM and stored in the two dimensional array
R.
Note that a dimension (DIM) statement was not required in this case since no subscript
value will exceed
9.
Line
58"
The first FOR statement
in
this line begins a loop that calculates the median
for each day of the week. Since there are five days, the index variable D runs from
1
to
5.
The second FOR statement in this line begins a loop that transfers the six weeks
of
data for day into a single dimension array
S.
Line
68
For a given week
Wand
day of the week D, the data value
is
transferred
from the two dimensional array R into the one dimensional array
S.
The data for the
first week will be transferred to
SO)'
the second week to S(2) and so on.
Line 78 The inner loop which transfers the six data values from the two dimensional
array
to
the one dimensional array is terminated.
Line 88 This line contains a new statement: GOSUB. When this statement is
executed, the program jumps to line
500. Lines 500 through 570 sort and compute the
median
of
the one dimensional arrays S. The median
is
stored in the variable MD (line
560). When line 570 is executed, the program jumps back to the statement following
the GOSUB statement. The block of statements in lines
500 through 570 are called a
subroutine. This particular subroutine computes the median
of
the one dimensional
array
8(1), 8(2), ... 8(N).
The value
of
the median is stored
in
the variable MD. It
was
necessary, in lines 50 -
70 , to store column D of the two dimensional array R in the one dimensional array S
because the subroutine computes the median
of
this specific one dimensional array.
Line 98 The value
of
the median for day D, which was placed
in
the variable
MD
in
the subroutine, is stored
in
the array M(D). This
is
done hecause the next median
calculated will be placed in MD, replacing the previous value
of
MD, before the
program displays the result.
Line
lee
This line terminates the FOR / NEXT loop which began
in
the first FOR
statement in line 50.
Line 118 The heading MEDIAN SALES
is
displayed. The TAB function
is
used
to
center the heading.
142