Download Courtesy to all ATARI 8 Bit Users

Transcript
Kyan PASCAL Version 1.0
The first array, String, may be used to handle words or phrases that have 15 characters, including blanks. Integers (1 to 15)
identify the elements of the array.
The second array declares that each vector consists of 3 numbers. (Each one is a direction in three-dimensional space.)
The elements of this array are identified not by Integers, but by CoordnType, a user-defined type. Any scalar type may index
an array.
Arrays of Arrays and Multidimensional Arrays
If we wished to represent a paragraph that contained up to 50 words, we might define it as an array of String (i.e., an array
of an array):
TYPE
String = ARRAY[1..15] OF Char ;
Paragraph = ARRAY[1..50] OF String;
Use of the array Paragraph could prove to be a wasteful programming technique because it reserves a lot of memory space
for what might turn out to be a short paragraph.
The array Paragraph is an example of a multidimensional array. The array MatxType below is also multidimensional.
MatxType is a two-dimensional array of numbers. (It is not necessary for the dimensions of the matrix to be the same size,
although in this one they are, 3 elements each.)
Two ways of declaring MatxType are:
TYPE
Row - ARRAY[1..3] OF Real;
MatxType ARRAY[1..3] OF ROW;
(*Each element of MatxType is a row*)
TYPE
MatxType = ARRAY[1..3, 1..3] OF Real;
(*Subscripts are row number, column number*)
It is important to recognize which subscript refers to which dimension in such arrays. The significance of this is illustrated by
the following example, in which a name, i.e., a string, is copied from a list:
TYPE
String = ARRAY[1..14] OF Char;
TableType = ARRAY[1..100]] OF String;
VAR
Table : TableType; Name : String; I : Integer;
BEGIN
FOR I : = 1 TO 14 DO
Table[2,I] := Name[I]
(*Name is written into the second row of table*)
END.
One way to remember which subscript is first is to rewrite the declaration of the array type. The first subscript type in the
declaration below gives the first subscript, S, in Table[S,P]; the second subscript type gives the second subscript, P.
TYPE
TableType ARRAY[1..100] OF ARRAY[1..14 OF Char;
Scanned & Re-Edited by GoodByte in 2005 / (P) 2006
41