-- Chapter 20 - Program 4 with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure Discrim4 is type SQUARE is array(INTEGER range <>, INTEGER range <>) of INTEGER; type LINEAR_TYPE is array(INTEGER range <>) of POSITIVE; subtype SMALL_POS is POSITIVE range 1..20; type STUFF(List_Length : SMALL_POS := 3; List_Width : SMALL_POS := 5; Linear_Size : SMALL_POS := 7) is record Matrix : SQUARE(1..List_Length, 1..List_Width); Elements : INTEGER := List_Length * List_Width; Linear : LINEAR_TYPE(1..Linear_Size); Number : INTEGER := Linear_Size; end record; Data_Store : STUFF(5, 5, 5); Big_Store : STUFF(12, 12, 12); Different : STUFF(5, 7, 4); More_Store : STUFF(Linear_Size => 15, List_Length => 6, List_Width => 2); Variable : STUFF; function Add_Elements(In_Array : STUFF) return INTEGER is Total : INTEGER := 0; begin for Index1 in In_Array.Matrix'RANGE(1) loop for Index2 in In_Array.Matrix'RANGE(2) loop Total := Total + In_Array.Matrix(Index1, Index2); end loop; end loop; return Total; end Add_Elements; procedure Set_To_Ones(Work_Array : in out STUFF) is begin for Index1 in Work_Array.Matrix'RANGE(1) loop for Index2 in Work_Array.Matrix'RANGE(2) loop Work_Array.Matrix(Index1, Index2) := 1; end loop; end loop; end Set_To_Ones; begin for Index1 in 1..Data_Store.List_Length loop Data_Store.Linear(Index1) := Index1; for Index2 in 1..Data_Store.List_Width loop Data_Store.Matrix(Index1, Index2) := Index1 * Index2; end loop; end loop; Variable := Data_Store; Put("The total of Variable is"); Put(Add_Elements(Variable), 6); New_Line; Variable := More_Store; Set_To_Ones(Big_Store); Set_To_Ones(Different); Set_To_Ones(More_Store); Set_To_Ones(Variable); Put("The total of Variable is"); Put(Add_Elements(Variable), 6); New_Line; Variable := Different; Put("The total of Variable is"); Put(Add_Elements(Variable), 6); New_Line; end Discrim4; -- Result of execution -- The total of Variable is 225 -- The total of Variable is 12 -- The total of Variable is 35