Integer, + - * DIV MOD, IF, FOR, WHILE, RdInt, WrInt.
MODULE HelloWorld;
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt; (* import general procedures *)
BEGIN
WrStr("Hello World");
WrLn;
END HelloWorld.
MODULE FirstVars;
FROM IO IMPORT
WrStr, WrLn, RdCard, WrCard,
RdInt,
WrInt; (* import general procedures *)
VAR a, b, x :
INTEGER;
BEGIN
a := 2;
b := 10;
x := (a + b) / 2;
WrStr("The Average is:");
WrLn;
WrInt(x, 0);
WrLn;
END FirstVars.
MODULE FirstInput;
FROM IO IMPORT
WrStr, WrLn, RdCard, WrCard,
RdInt,
WrInt; (* import general procedures *)
VAR a, b, x :
INTEGER;
BEGIN
WrStr("Give the first number");
WrLn;
a := RdInt();
WrStr("Give the
second number");
WrLn;
b := RdInt();
x := (a + b) / 2;
WrStr("The Average is:");
WrLn;
WrInt(x, 0);
WrLn;
END FirstInput.
MODULE D1part1;
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt; (* import general procedures *)
VAR x:CARDINAL; (* variable-declarations *)
BEGIN
WrStr("Please give me a number");
WrLn;
x := RdCard();
IF ((x MOD 7) = 0) THEN
WrCard(x, 0);
WrStr(" is divisible by
7");
ELSE
WrCard(x, 0);
WrStr(" is not divisible
by 7");
END;
WrLn;
END D1part1.
MODULE D1part2;
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt; (* import general procedures *)
VAR x:CARDINAL; (* variable-declarations *)
BEGIN
WrLn;
WrStr("Please give me a number");
WrLn;
x := RdCard();
IF (x <= 10000) THEN
WrStr("x must be greater
than 10000!");
WrLn;
ELSE
IF ((x MOD 7) = 0) THEN
WrCard(x, 0);
WrStr(" is
divisible by 7");
ELSE
WrCard(x, 0);
WrStr(" is
not divisible by 7");
END;
WrLn;
END;
END D1part2.
MODULE D1part3;
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt; (* import general procedures *)
VAR x, i:CARDINAL; (* variable-declarations *)
BEGIN
WrLn;
FOR i := 1 TO 5 DO
WrStr("Iteration: ");
WrCard(i,1);
WrLn;
WrStr("Please give me a number");
WrLn;
x := RdCard();
IF (x <= 10000) THEN
WrStr("x must be greater
than 10000!");
WrLn;
ELSE
IF ((x MOD 7) = 0) THEN
WrCard(x, 0);
WrStr(" is
divisible by 7");
ELSE
WrCard(x, 0);
WrStr(" is
not divisible by 7");
END;
WrLn;
END;
END;
END D1part3.
MODULE D1part4;
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt; (* import general procedures *)
VAR x, i:CARDINAL; (* variable-declarations *)
BEGIN
WrLn;
i := 0;
REPEAT
i := i + 1;
WrStr("Iteration: ");
WrCard(i,1);
WrLn;
WrStr("Please give me a number
greater
than 10000 and divisible by 7:");
x := RdCard();
IF (x <= 10000) THEN
WrStr("x must be greater
than 10000!");
WrLn;
ELSE
IF ((x MOD 7) = 0) THEN
WrCard(x, 0);
WrStr(" is
divisible by 7");
ELSE
WrCard(x, 0);
WrStr(" is
not divisible by 7: try again");
END;
WrLn;
END;
UNTIL ((x > 10000) AND ((x MOD 7) = 0));
IF (i < 7) THEN
WrStr("Congratulations: you've found
one after ");
WrCard(i,1);
WrStr(" trials!");
WrLn;
ELSE
WrStr("You've only found one after
");
WrCard(i,1);
WrStr(" trials!??");
WrLn;
END;
END D1part4.
MODULE D1part5;
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt; (* import general procedures *)
VAR x, i, divisibleBy:CARDINAL; (* variable-declarations *)
BEGIN
WrLn;
WrStr("Please give me a number: ");
divisibleBy := RdCard();
WrLn;
i := 0;
REPEAT
i := i + 1;
WrStr("Iteration: ");
WrCard(i,1);
WrLn;
WrStr("Please give me a number
greater
than 10000 and divisible by ");
WrCard(divisibleBy,1);
WrStr(": ");
x := RdCard();
IF (x <= 10000) THEN
WrStr("x must be greater
than 10000!");
WrLn;
ELSE
IF ((x MOD divisibleBy)
= 0) THEN
WrCard(x, 0);
WrStr(" is
divisible by ");
WrCard(divisibleBy,1);
ELSE
WrCard(x, 0);
WrStr(" is
not divisible by ");
WrCard(divisibleBy,1);
WrStr(": try
again");
END;
WrLn;
END;
UNTIL ((x > 10000) AND ((x MOD divisibleBy) =
0));
IF (i < divisibleBy) THEN
WrStr("Congratulations: you've found
one after ");
WrCard(i,1);
WrStr(" trials!");
WrLn;
ELSE
WrStr("You've only found one after
");
WrCard(i,1);
WrStr(" trials!??");
WrLn;
END;
END D1part5.
MODULE D1part6;
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt; (* import general procedures *)
VAR x, i, divisibleBy, greaterThan:CARDINAL; (* variable-declarations *)
BEGIN
WrLn;
WrStr("Please give me a number: ");
divisibleBy := RdCard();
WrLn;
WrStr("Please give me a second number: ");
greaterThan := RdCard();
WrLn;
i := 0;
REPEAT
i := i + 1;
WrStr("Iteration: ");
WrCard(i,1);
WrLn;
WrStr("Please give me a number
greater
than ");
WrCard(greaterThan,1);
WrStr(" and divisible by ");
WrCard(divisibleBy,1);
WrStr(": ");
x := RdCard();
IF (x <= greaterThan) THEN
WrStr("x must be greater
than ");
WrCard(greaterThan,1);
WrStr("!");
WrLn;
ELSE
IF ((x MOD divisibleBy)
= 0) THEN
WrCard(x, 0);
WrStr(" is
divisible by ");
WrCard(divisibleBy,1);
ELSE
WrCard(x, 0);
WrStr(" is
not divisible by ");
WrCard(divisibleBy,1);
WrStr(": try
again");
END;
WrLn;
END;
UNTIL ((x > greaterThan) AND ((x MOD
divisibleBy)
= 0));
IF (i < divisibleBy) THEN
WrStr("Congratulations: you've found
one after ");
WrCard(i,1);
WrStr(" trials!");
WrLn;
ELSE
WrStr("You've only found one after
");
WrCard(i,1);
WrStr(" trials!??");
WrLn;
END;
END D1part6.
MODULE S6;
<* NOOPTIMIZE + *>
FROM IO IMPORT WrStr, WrLn, RdCard, WrCard, RdInt, WrInt,
RdKey, RdLn;
FROM Graph IMPORT Init, Rectangle, Circle, Line, Disc,
RawOutText;
FROM Graph IMPORT _clrBLACK, _clrWHITE, _clrGREEN, _clrCYAN,
_clrMAGENTA;
FROM Graph IMPORT _clrBROWN, _clrRED, _clrGRAY,
_clrLIGHTBLUE,
_clrLIGHTGREEN;
CONST N = 5;
VAR
c:CHAR;
i:CARDINAL;
BEGIN
(* Initialise graphics. Coordinatesystem: (0,0) is the
top
left corner *)
IF NOT Init(0, 0 , 420, 430) THEN
WrStr("Sorry, graphics doesn't work");WrLn;
RETURN;
END;
(* Plot figures... *)
Line(0, 200, 200, 0, _clrWHITE);
Line(200, 0, 400, 200, _clrWHITE);
Line(400, 200, 200, 400, _clrWHITE);
Line(200, 400, 0, 200, _clrWHITE);
(* Show graphics until user presses a key *)
WrStr("Press any key to finish the program");
c := RdKey();
WrLn; RdLn;
END S6.
Solution:
3
33
18
Debugging tips: