Solutions TOPIC B: Arrays

Contents :

   ARRAY of INTEGERS,  CONST.

D1

Exercise

MODULE D1a;
<* WOFF + *> (* geen warnings *)

    FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt;     (* import general procedures *)

    VAR
      arr: ARRAY[1..10] OF INTEGER;            (* variable-declarations *)
      i:CARDINAL;

BEGIN
    (* Fill array *)
    FOR i := 1 TO 10 DO
      arr[i] := 1;
    END;

    (* Print array *)
    FOR i := 1 TO 10 DO
      WrStr("Element "); WrCard(i, 0); WrStr(" of array is: "); WrInt(arr[i],0); WrLn;
    END;

END D1a.



MODULE D1b;
<* WOFF + *> (* geen warnings *)

    FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt;     (* import general procedures *)

    CONST LENGTE = 20;       (* constants *)  
    VAR

      arr: ARRAY[1..LENGTE] OF INTEGER;            (* variable-declarations *)
      i:CARDINAL;

BEGIN
    WrLn;
    (* Fill array *)
    FOR i := 1 TO LENGTE DO
      arr[i] := i;
    END;

    (* Print array *)
    FOR i := 1 TO LENGTE DO
      WrStr("Element "); WrCard(i, 0); WrStr(" of array is: "); WrInt(arr[i],0); WrLn;
    END;

END D1b.



D2

MODULE D2;
<* NOOPTIMIZE + *>  (* voor de Debugger *)
<* WOFF + *> (* geen warnings *)

FROM RealMath IMPORT power, arctan, pi, cos, sin, sqrt;
FROM JJ3D IMPORT StartMy3DWorld, DrawEverything, ClearScreen,
Delay, WaitUntilQPressed, WrStr, WrCard, WrInt, WrReal, WrBool, WrLn;
FROM JJ3D IMPORT Plot, Line, ThickLine, PlotText, Triangle, RectangleXY, RectangleYZ, RectangleXZ, Polygon, Cube, Block, Cilinder, Arrow3D;
FROM JJ3D IMPORT
RgbColor, Lighter, Darker, RED, GREEN, BLUE, CYAN, MAGENTA, GRAY, BROWN;
FROM JJ3D IMPORT BLACK, BRIGHTWHITE, WHITE, LIGHTRED, LIGHTGREEN, LIGHTBLUE, LIGHTCYAN, LIGHTMAGENTA, LIGHTYELLOW;

CONST  DELAY_TIME = 1000;

  VAR


BEGIN
  StartMy3DWorld("Mijn 3D-wereld") ;

   Cilinder(-100, 100, 0, 20, 400, Lighter(RED, 30), TRUE);
   DrawEverything();
   
   Delay(DELAY_TIME);

   ClearScreen();
   Cube(450, 300, 100, 200, RgbColor(200, 100, 50), TRUE);
     DrawEverything();   
   
   Delay(DELAY_TIME);

   ClearScreen();
   Block(500, 0, 0, 100, 100, 200, LIGHTYELLOW, FALSE);
     DrawEverything();
   
   Delay(DELAY_TIME);

   ClearScreen();
   Cilinder(-100, 100, 0, 20, 400, Lighter(RED, 30), TRUE);       
  DrawEverything();

       
  WaitUntilQPressed();

END D2. 


S2

Exercise

  MODULE S2;
<* NOOPTIMIZE + *>  (* voor de Debugger *)
<* WOFF + *> (* geen warnings *)
FROM RealMath IMPORT power, arctan, pi, cos, sin, sqrt;
FROM JJ3D IMPORT StartMy3DWorld, DrawEverything, ClearScreen,
Delay, WaitUntilQPressed, WrStr, WrCard, WrInt, WrReal, WrBool, WrLn;
FROM JJ3D IMPORT Plot, Line, ThickLine, PlotText, Triangle, RectangleXY, RectangleYZ, RectangleXZ, Polygon, Cube, Block, Cilinder, Arrow3D;
FROM JJ3D IMPORT
RgbColor, Lighter, Darker, RED, GREEN, BLUE, CYAN, MAGENTA, GRAY, BROWN;
FROM JJ3D IMPORT BLACK, BRIGHTWHITE, WHITE, LIGHTRED, LIGHTGREEN, LIGHTBLUE, LIGHTCYAN, LIGHTMAGENTA, LIGHTYELLOW;


 CONST LENGTE = 10;
    F1 = TRUE;   (* bepaalt keuze van functie *)

  VAR
    i: INTEGER;
    x, z: ARRAY[1..LENGTE] OF INTEGER; (* definitie van een array *)       
    color: INTEGER;

BEGIN
  StartMy3DWorld("Mijn 3D-wereld") ;

  FOR i:= 1 TO LENGTE DO
      x[i] := i * 20;
      IF F1 THEN
        z[i] := 20 * i - 4 * i * i + i * i  * i /5 - i * i * i * i / 370;
      ELSE (* tweede functie *)
        z[i] := -  i*2/3 + i * i - i*i*i/67;
      END;
  END;
  (* ZET JE CODE HIER *)   
                                                
                                                           

   
       
  DrawEverything();

       
  WaitUntilQPressed();

END S2.


S3

Exercise


H1


 

T1

Exercise