Solutions TOPIC D: Multidimensional arrays

Contents :

  Multidimensional arrays.

Exercises :


D1

Exercise

MODULE D1Part1;
<* NOOPTIMIZE + *>
    FROM IO IMPORT RdChar, WrChar, WrStr, RdStr, WrLn, RdCard, WrCard, RdInt, WrInt;     (*
import general procedures *)

    CONST N = 3;          (* constants *)

    VAR A, B: ARRAY[1..N],[1..N] OF INTEGER;            (* variable-declarations *)
      i, j: INTEGER;
BEGIN
    WrLn;
    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        A[i][j] := i + j;
        B[i][j] := i - j;
      END;
    END;

    WrStr("Matrix A:"); WrLn;
    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        WrInt(A[i][j], 5);
      END;
      WrLn;
    END;

    WrStr("Matrix B:"); WrLn;
    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        WrInt(B[i][j], 5);
      END;
      WrLn;
    END;

END D1Part1.

MODULE D1Part2;
<* NOOPTIMIZE + *>
    FROM IO IMPORT RdChar, WrChar, WrStr, RdStr, WrLn, RdCard, WrCard, RdInt, WrInt;     (*
import general procedures *)

    CONST N = 3;          (* constants *)

    VAR A, B, C: ARRAY[1..N],[1..N] OF INTEGER;            (* variable-declarations *)
      i, j: INTEGER;
BEGIN
    WrLn;
    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        A[i][j] := i + j;
        B[i][j] := i - j;
      END;
    END;

    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        C[i][j] := A[i][j] + B[i][j];
      END;
    END;

    WrStr("Matrix A:"); WrLn;
    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        WrInt(A[i][j], 5);
      END;
      WrLn;
    END;

    WrStr("Matrix B:"); WrLn;
    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        WrInt(B[i][j], 5);
      END;
      WrLn;
    END;

    WrStr("Matrix C:"); WrLn;
    FOR i := 1 TO N DO
      FOR j := 1 TO N DO
        WrInt(C[i][j], 5);
      END;
      WrLn;
    END;

END D1Part2.


S1

Exercise

S2

Exercise

S3

Exercise

S5

Exercise

MODULE S5;
<* NOOPTIMIZE + *>
  FROM IO IMPORT RdChar, WrChar, WrStr, RdStr, WrLn, RdKey, RdLn, RdCard, WrCard, RdInt,
WrInt, RdReal, WrReal;
  FROM Lib IMPORT Delay; (* Delay: let the program wait a little time *)
      (* de graphics library vind je onder C:/Bin/Xds/Def/Ts/Graph.def *)
  FROM Wimdows IMPORT Window, KillWindow, GetKey, Rectangle, Circle, Disc, SetPixel;
  FROM Wimdows IMPORT _clrBLACK, _clrBLUE, _clrGREEN, _clrCYAN, _clrRED, _clrMAGENTA;
  FROM Wimdows IMPORT _clrBROWN, _clrWHITE, _clrGRAY, _clrLIGHTBLUE, _clrLIGHTGREEN;
  FROM Wimdows IMPORT _clrLIGHTCYAN, _clrLIGHTRED, _clrLIGHTMAGENTA, _clrLIGHTYELLOW,
_clrBRIGHTWHITE;
                 (* deze 16 kleuren zijn constantes gaande van 0 tot 15 *)
  CONST BITMAP_SIZE = 32;
     SCREEN_SIZE = 700;

  VAR
   x:CARDINAL;
   hunter: ARRAY [1..BITMAP_SIZE],[1..BITMAP_SIZE] OF CHAR;
   colorMap: ARRAY['a'..'h'] OF CARDINAL;
BEGIN

  (* Initialise graphics. Coordinatesystem: (0,0) is the top left corner *)
  Window("bitmaps", SCREEN_SIZE, SCREEN_SIZE);

  (* color array defintion *)
  colorMap['a'] :=_clrBRIGHTWHITE;
  colorMap['b'] := _clrLIGHTYELLOW; (* Yellow *)
  colorMap['c'] := _clrBLACK; (* Black *)
  colorMap['d'] := _clrRED; (* Red *)
  colorMap['e'] := _clrGRAY; (* Gray *)
  colorMap['f'] := _clrBRIGHTWHITE; (* White *)
  colorMap['g'] := _clrBROWN; (* Brown *)
  colorMap['h'] :=_clrBRIGHTWHITE;

  (* bitmap definition *)
  hunter[1]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[2]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[3]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[4]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[5]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[6]:="aaaaaaaaaaaaabbbbbbbaaaaaaaaaaaa";
  hunter[7]:="aaaaaaaaaaabbbbbbbbbbbaaaaaaaaaa";
  hunter[8]:="aaaaaaaaaabccbbbbbbbbbbaaaaaaaaa";
  hunter[9]:="aaaaaaaaabbbccccbbbbbbbbaaaaaaaa";
  hunter[10]:="aaaaaaaabbbbbbbcccbbbbbbbaaaaaaa";
  hunter[11]:="aaaaaaabbbbbbbbbbcccbbbbbbaaaaaa";
  hunter[12]:="aaaaaabbbbbbbbbbbbbcccbbbbbaaaaa";
  hunter[13]:="aaaaaabbbbbbdcbbbbbccccbbbbaaaaa";
  hunter[14]:="aaaaabbbbbbddccbbbbccccccbbbaaaa";
  hunter[15]:="aaaaabbbbbbccccbbbbcccccccccaaaa";
  hunter[16]:="aaaaabbbbbbbccbbbbbccccbbbbcaaaa";
  hunter[17]:="aaaaabbbbbbbbbbbbbbbbbbbbbbbaaaa";
  hunter[18]:="aaaaabbbbbbbbbbbbbbbbbbbbbbbaaaa";
  hunter[19]:="aaaaabbbbbbbbbbbbbbbbbdbbbbbaaaa";
  hunter[20]:="aaaaabbbbbbbbbbbbbbbebdbbbbbaaaa";
  hunter[21]:="aaaaaaeeeeeeeefffffeeedggggggaaa";
  hunter[22]:="aaaaddeeffffffeeeeeeeddggggggaaa";
  hunter[23]:="aaaaaaeeeeeeeeeeeeeeeedggggggaaa";
  hunter[24]:="aaaaaaaabbbbbbbbbbbbbbdbbaaaaaaa";
  hunter[25]:="aaaaaaaaabbbbbbbbbbbbbbbaaaaaaaa";
  hunter[26]:="aaaaaaaaaabbbbbbbbbbbbbaaaaaaaaa";
  hunter[27]:="aaaaaaaaaaabbbbbbbbbbbaaaaaaaaaa";
  hunter[28]:="aaaaaaaaaaaaabbbbbbbaaaaaaaaaaaa";
  hunter[29]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[30]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[31]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
  hunter[32]:="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

  (* Plot figure... *)
 

  (* Show graphics until user presses a key *)
  x := GetKey();
  KillWindow();


END S5.


X1

Exercise
 
  1. 4 errors:
  2. mail your solution to me!!



H1

Exercise

H2

Exercise

T1

Exercise