Sinclair QL Beginner's Manual page 91

Hide thumbs Also See for QL:
Table of Contents

Advertisement

The following program places the ten golfers in an array named flat$ and prints the names of the
occupants with their 'flat numbers' (array subscripts) to prove that they are in residence. The
occupants of flats 1 and 3 then change places. The list of occupants is then printed again to show that
the exchange has occurred.
100 REMark Golfers' Flats
110 DIM flat$(10,8)
120 FOR number = 1 TO 10 : READ flat$(number)
130 printlist
140 exchange
150 printlist
160 REMark End of main program
170 DEFine PROCedure printlist
180 FOR num = 1 TO 10 : PRINT num,flat$(num)
190 END DEFine
200 DEFine PROCedure exchange
210 LET temp$ = f1at$(1)
220 LET flat$(1) = f1at$(3)
230 LET flat$(3) = temp$
240 END DEFine
250 DATA "Tom","Graham","Sevvy","Jack","Lee"
260 DATA "Nick","Bernard","Ben","Greg","Hal"
output (line 130)
1
Tom
2
Graham
3
Sevvy
4
Jack
5
Lee
6
Nick
7
Bernard
8
Ben
9
Gregg
10 Hal
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 f lats 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:
output (line 150)
1
Sevvy
2
Graham
3
Tom
4
Jack
5
Lee
6
Nick
7
Bernard
8
Ben
9
Gregg
10 Hal

Advertisement

Table of Contents
loading

Table of Contents