6/Arrays
An
array is simply an orderedlist
of
values. In Model
III
BASIC these values may be
either numbers
or
strings, depending on how the array is definedor typed. Arrays
provide a
fast
and
organizedway
of
handling large amounts
of
data. To illustrate
the
power
of
arrays, this chapter traces the development
of
an array to store
checkbookdata: checknumbers, dates written, and
amountsfor
each check.
In addition, several
matrix manipulation subroutines are listed at the end
of
this
chapter. These sequences will letyou add, multiply, transpose, andperform other
operations
on
arrays.
Note: Throughout this chapter, zero-subscripted elements are generally ignored
for
the sake
of
simplicity.
But
you should remember they are available and should
be
usedfor
the
most
efficient use
of
memory. For example, after
DIM
A(4), array A
contains5 elements: A(O), A(1), A(2), A(3), A(4).
For
backgroundinformation on arrays, see Chapter4, DIM, andChapter 1,
,'Arrays' ,.
ACheck-Book
Array
Considerthe following table
of
checkbook information:
Check # Date Written
Amount
025
026
027
028
029
030
1-1-78
1-5-78
1-7-78
1-7-78
1-10-78
1-15-78
10.00
39.95
23.50
149.50
4.90
12.49
Note thatevery itemin the table may be specified simply by reference to two
numbers: the row number and the column number. For example, (row 3, column 3)
refers to the amount23.50. Thus the numberpair (3,3) may be called
the'
'subscript
address',
of
the value 23.50.
Let's
setup an array,
CK,
to correspondto the checkbook information table. Since
the table contains 6 rows and 3 columns, array
CK will need two dimensions: one for
row numbers, and one for column numbers.
We
can picture the array like this:
A(l,1)
=025
A(6,l)
=030
A(l
,2) = 1.0178
A(6,2) = 1.1578
A(l.3)
= 10.00
A(6,3) 12.49
6/1