MODULE Showcase11; (* Standard-library tour: SysIO, TextIO, WholeIO, Strings, Math, Files. Reads one CARDINAL from stdin (e.g. 42). Prints: Modula-2 / 8 / 42 / 12 / 42 ; exit 80. *) IMPORT Files; FROM Files IMPORT File; FROM Math IMPORT sqrt, Pi; FROM Strings IMPORT Assign, Concat, Length; FROM SysIO IMPORT Write, WriteInt, WriteLn; FROM TextIO IMPORT WriteCard; FROM WholeIO IMPORT ReadCard; VAR ExitCode : INTEGER; VAR s, t, u : ARRAY [0..31] OF CHAR; VAR r : REAL; VAR f : File; VAR n : INTEGER; VAR card : CARDINAL; BEGIN (* Strings: build "Modula-2" and report its length. *) Assign("Modula", s); Assign("-2", t); Concat(s, t, u); Write(u); WriteLn; WriteInt(Length(u)); (* 8 *) WriteLn; (* WholeIO input + TextIO output: echo the read card. *) ReadCard(card); WriteCard(card); (* 42 *) WriteLn; (* Math: sqrt(144) = 12. *) r := sqrt(144.0) + Pi - Pi; IF r > 11.9 THEN n := 12 ELSE n := 0 END; WriteInt(n); (* 12 *) WriteLn; (* Files: write two chars, read the integer back. *) f := Files.OpenWrite("gen_ssa/_showcase11.txt"); Files.WriteChar(f, '4'); Files.WriteChar(f, '2'); Files.Close(f); f := Files.OpenRead("gen_ssa/_showcase11.txt"); n := Files.ReadInt(f); Files.Close(f); WriteInt(n); (* 42 *) WriteLn; ExitCode := n - 12 + Length(u) + card END Showcase11.