Line 94 uses RESTORE to make the program read data beginning at line 280
or at 500, depending upon the set of questions are chosen.
Arrays
The computer is very useful for finding a particular data item in a long list or
for sorting sets of data into a particular order. For example, you might want to
sort a list of names into alphabetical order. The computer is quite able to do
this, but it needs to compare every name with every other name to decide upon
their order. All the names must be accessible at the same time, and it is easier
to compare them if they are all stored in a list or array.
This program reads 10 names into an array and then displays any selected
name:
10 MODE 135
20 PR0Cset_up_array
30 PR0Cfind
40 END
50 DEFPR0Cset_up_array
60 DIM name$(10)
70 FOR count=1 TO 10
80 READ name$(count)
90 NEXT count
10 ENDPROC
110 DATA Smith,BLoggs,Hutchings,Broome
120 DATA Turner,Dick,James,Neale,Sewell,van Someren
130 DEFPR0Cfind
140 INPUT "Which name do you want (1-10)",number
150 PRINT' "Number " ;number;" in the list is ";name$(number)
160 ENDPROC
The DIM statement in line 60 tells the computer how many items there are in
the array -- in this case, 10. The loop from lines 70 to 90 reads the names from
data statements and automatically stores them in the array name$, so that
name$(l) is Smith, name$(2) is Bloggs, and so on. PROCfind at 130 is included
so that you can confirm for yourself that the computer has stored the names in
the order they are given in the DATA statements.
The program can search through the array very rapidly to find a name or set of
names which meet certain requirements. For example, to find all names
beginning with a particular letter, change the last few lines to:
140 INPUT "Which letter shoutd the name begin with " ,letter$
150 FOR count=1 TO 10
160 name$=name$(count)
C 52