Chapter 8

1. (a) An array is a collection of numeric or string variables,
all having the same name and distinguished from one another by
a numeric index.
(b) An array element is one of the individual numeric
or string variables that make up the array.
(c) Dimension refers to the format of the array; a one-
dimensional array is displayed as a list and has a single index,
a two-dimensional array is usually displayed as a table and has
two indices.
(d) The size of a dimension is the number of elements in that
dimension; for example, the number of items in a list or the number
of rows or columns in a table.

2. (a) If an array is dimensioned with the statement DIM Name$(50),
a value cannot be assigned to element Name$(0) because the first
element in the array is Name$(1).
(b) Any string value can be assigned to element Name$(50).

3. The statement DIM Bound(N), where N is 7, is not a valid
statement because the dimension arguments of an array must be
dimensioned by constants, not variables.

4. An array dimensioned by the statement DIM Value(-5:5)
contains 11 elements.

5. An array is dimensioned by the statement DIM Structure(5)
and has positive values assigned to its elements. The statement
"FOR I = 0 to Structure(3)" is a legal statement, with variable I
running from 0 to the value of element Structure(3) in steps of +1.

6. (a) DIM Array(15) is a valid statement and has one dimension.
(b) DIM Array(1,15) is valid and has two dimensions.
(c) DIM Array(1;15) is not valid, semicolon is not allowed.
(d) DIM Array(1-15) is not valid, a dash or hyphen is not
allowed.
(e) DIM Array(1 to 15) is valid.
(f) DIM Array(1 through 15) is not valid, the word "through"
is not allowed.

7. If an array is dimensioned with the statement DIM List$(100),
the value of UBOUND(List$) is 100 and the value of LBOUND(List$)
is 1.

8. A one-dimensional array named Structure is passed to an
external subroutine named Analyze.

(a) The proper call statement is CALL Analyze (Structure).
(b) The proper heading statement is EXTERNAL SUB Analyze (List()).

9. If an array is dimensioned in the main program and passed as
a parameter to an external function, it cannot be dimensioned again
in the function unit.

10. An array can only be dimensioned once in a program. The
DIM statement in the example program should be moved outside the
loop, as shown below:

DIM Num(5)
FOR I = 1 to 5
LET Num(I) = 0
NEXT I
END

11. (a) The statement EXTERNAL SUB Capital(List$(,)) has the
correct syntax.
(b) The array List$ has two dimensions.

12. (a) The function UBOUND(Result, 2) returns the upper-bound
value of the second dimension of Result.
(b) The function LBOUND(Result, 2) returns the lower-bound
value of the same dimension.

13. The principal diagonal is defined only for square arrays
where the number of rows equals the number of columns. It is the
diagonal line of elements running from the upper left corner
of the array to the lower right corner.

14. Elements along the principal diagonal have the same value
for both indices.

15. An array representing a table and dimensioned DIM Table(5,3)
has 5 rows and 3 columns.

16. The example program will not work because the I loop and
the J loop overlap. It should be written as follows:

DIM Table(5,3)
FOR I = 1 to 5
FOR J = 1 to 3
LET Table(I,J) = 0
NEXT J
NEXT I
END

17. The array is not displayed as a table with 5 rows and 5
columns. An extra PRINT statement is needed to start each new row.
Here is a corrected program:

DIM Mileage(5,5)
FOR I = 1 to 5
FOR J = 1 to 5
PRINT Mileage(I,J);
NEXT J
PRINT ! start a new row
NEXT I
END

18. A program contains the statement DIM Mileage(5, 5),
List$(1 to 50).

(a) MAT Mileage = nul$(7,7) is not valid, NUL$ can be
used only with string arrays.
(b) MAT redim Mileage(5) is not valid, redim cannot
change the number of dimensions.
(c) MAT redim List$(1:100) is a valid statement.
(d) MAT List$ = zer(1 to 10) is not valid, ZER can be
used only with numeric arrays.