The Ada Program: drill.adb
1 with Ada.Text_IO, Ada.Float_Text_IO, Ada.Integer_Text_IO;
2 use Ada;
3 with Ada.Numerics.Elementary_Functions;
4 use Ada.Numerics.Elementary_Functions;
5
6 procedure Drill is
7 type Location is record
8 X,Y: Float;
9 Drilled: Boolean := False;
10 end record;
11 function Distance (A,B: Location) return Float is
12 begin
13 return (Sqrt ((A.X-B.X)**2 + (A.Y-B.Y)**2));
14 end Distance;
15 type Data_Array is array (Positive range <>) of Location;
16 procedure Find_Next (Next: in out Integer; Data: Data_Array) is separate;
17 N: Integer;
18 begin
19 Text_IO.Put ("How many points? ");
20 Integer_Text_IO.Get (N);
21 declare
22 Data : Data_Array (1..N);
23 Next : Integer := Data'First;
24 begin
25 Text_IO.Put_Line ("Enter points.");
26 for I in Data'Range loop
27 Integer_Text_IO.Put (I); Text_IO.Put (": ");
28 Float_Text_IO.Get (Data(I).X);
29 Float_Text_IO.Get (Data(I).Y);
30 end loop;
31 Text_IO.Put_Line ("The points in order");
32 Integer_Text_IO.Put (Next); Text_IO.Put (": ");
33 Float_Text_IO.Put (Data(Next).X);
34 Float_Text_IO.Put (Data(Next).Y);
35 Text_IO.New_Line;
36 Data(Next).Drilled := True;
37 for I in Data'First+1 .. Data'Last loop
38 Find_Next (Next, Data);
39 Integer_Text_IO.Put (Next); Text_IO.Put (": ");
40 Float_Text_IO.Put (Data(Next).X);
41 Float_Text_IO.Put (Data(Next).Y);
42 Text_IO.New_Line;
43 Data(Next).Drilled := True;
44 end loop;
45 end;
46 end Drill;