Sinclair QL User Manual page 92

Hide thumbs Also See for QL:
Table of Contents

Advertisement

output (line 130)
1 Tom
2 Graham
3 Sevvy
4 J ac k
5 Lee
6 N
i
c
k
7 Bernard
8 Ben
9 Gregg
10
Ha
L
output (line 150)
1 Sevvy
2 Graham
3 Tom
4 J ac k
5 Lee
6 N
i
c
k
7 Bernard
8 Ben
9 Gregg
10
Ha
t
TWO DIMENSIONAL
ARRAYS
Sometimes the nature of a problem suggests two dimensions such as 3 floors of 10
flats rather than Just a single row of 30.
'
Suppose that 20 or more golfers need flats and there IS a block of 30 flats divided Into
three floors of ten flats each. A realistic method of representing the block would be with
a two-dimensional array. You can think of the thirty variables as shown below:
flat$(2.Q)
flat$(2,1)
flat$(2,2)
flat$(2,0)
D D
=~~~~s~~~:~~~~~~~D
flat$(1,0)
flat$(1,1)
f1at$(1,2)
flat$(1,9)
D D
=~~~~~~~S~(~)~~~~~~D
flat$(O,O)
flat$(0,1)
flat$(0,2)
flat$(0,9)
D D
=~~~~~~~:~~~~~~~D
Assuming DATA statements with 30 names, a sUitable way to place the names In the
flats is:
120 FOR floor = 0 TO 2
130
FOR num = 0 TO 9
140
READ fLats$(fLoor. num)
150
END FOR num
160 END FOR f toor
You also need a DIM statement:
20 DIM fLat$(2.9.8)
which shows that the first subscript can be from 0 to 2 (floor number) and the second
subscript can be from 0 to 9 (room number). The third number states the maximum
number of characters in each array element
We add a print routine to show that the golfers are in the flats and we use letters to
save space.
100 REMark 30 Golfers
110 DIM flat$(2,9,8)
120 FOR floor = 0 TO 2
130
FOR num = 0 TO 9
140
READ flat$(floor,num)
REMark GoLfer goes in
150
END FOR num
160 END FOR fLoor
170 REMark End of input
180 FOR floor
=
0 TO 2
190
PRINT "FLoor number"
I
fLoor
12/84

Advertisement

Table of Contents
loading

Table of Contents