The Ada Program: main.adb
1 -- main.adb: Ada program using several predefined libraries
2
3 with
4 Ada.Command_Line, -- External execution env (Ada95 A.15)
5 Ada.Text_IO, -- Text (Latin 1) input/output (Ada95 A10.1)
6 Ada.Integer_Text_IO, -- Preinstantiated generic for Integer IO
7 Ada.Text_IO.Editing, -- Picture-directed editing (Ada95 F3.3)
8 Ada.Numerics.Float_Random,-- Random numbers (Ada95 A5.2)
9 Lower; -- Separately compiled function
10
11 use Ada, Ada.Numerics;
12
13 procedure Main is
14
15 First_Argument : constant String := Command_Line.Argument(1);
16
17 type Decimal is delta 0.01 digits 8; -- decimal fixed-point type
18 package Decimal_IO is new Text_IO.Editing.Decimal_Output (Num=>Decimal);
19
20 G: Float_Random.Generator;
21 function Next return Decimal is
22 begin
23 return (Decimal (Float_Random.Random(G)*Float(Decimal'Last)));
24 end Next;
25
26 Value: Decimal;
27
28 begin
29
30 -- covert first command line argument to all lower case
31 for I in First_Argument'Range loop
32 Text_IO.Put (Lower(First_Argument(I)));
33 end loop;
34 Text_IO.New_Line;
35
36 -- print random fixed point number in two different forms
37 Float_Random.Reset (G);
38 Value := Next;
39 Decimal_IO.Put (Value, Text_IO.Editing.To_Picture ("ZZZ_ZZZ_ZZ9"));
40 Decimal_IO.Put (Value, Text_IO.Editing.To_Picture ("ZZZ_ZZZ_ZZ9.99"));
41 Text_IO.New_Line;
42
43 end Main;