Radio Shack TRS-80 Model 100 Basic Manual page 144

Basic language lab
Hide thumbs Also See for TRS-80 Model 100:
Table of Contents

Advertisement

Line 620 The loop which begins in this line displays the five values in row R of the
table.
Line
630 The value of the subscript I in the S array is computed for the element
displayed in row R and column C. For example, if R
=
3 and C
=
2, then I
=
12.
This is necessary because the data is stored in a one dimensional array but displayed
in a two dimensional table.
Line 640 The value in row R and column C is displayed. The TAB statement is used
to space the output. Note that the semicolon after S(I) suppresses the carriage return.
Line
650 The first statement in this line terminates the inner loop which displayed the
entries in row R. The PRINT statement generates a carriage return, so that the next
five values will be displayed on the next line.
Line
660 The outer loop, which displays each of the six rows, is terminated.
Sorting data is frequently required in computer programming. The bubble sort
technique introduced in this experiment is a straightforward approach to this common
problem, and is well worth learning. Once the sales data has been sorted, it is quite
easy to compute another measure of central tendency -
the median.
Experiment #5 Computing the Median
Now that you know how to sort the sales data, you can easily change your program to
compute the median. The median is similar to the average in that they both measure
central tendency. The median is a number such that half of the data values are larger
than the median, and half of the data values are less than the median. If the data
values are sorted, the median is defined as follows
i) if there are an odd number of values, the median is the middle value
ii) if there are an even number of values, the median is the average of the two
middle values.
In the sales data example, there are 30 data values, (an even number) and the two
middle values are the 15th and 16th values. The median is the average of these two
values.
Delete lines 600 through 660 and add the following two lines to the program:
56121 MD
=
(5(15)
+
5(16» / 2
57121 PRINT "MEDIAN SALES"; MD
Execute the program. The values will be sorted as before, but not displayed. The
following will be displayed
MEDIAN SALES 28121
The median is another type of "average" which in many cases is a better measure of
central tendency than the mean. For example, the median is less affected by extreme
values than the mean. The median is the central value in the sense that there are just
as many values above it as below it.
138

Advertisement

Table of Contents
loading

Table of Contents