home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 20 - Program 3
- with Text_IO;
- use Text_IO;
-
- procedure Discrim3 is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- type SQUARE is array(INTEGER range <>,
- INTEGER range <>) of INTEGER;
-
- type LINEAR_TYPE is array(INTEGER range <>) of POSITIVE;
-
- type STUFF(List_Size : POSITIVE := 2) is
- record
- Matrix : SQUARE(1..List_Size,1..List_Size);
- Elements : INTEGER := List_Size * List_Size;
- Linear : LINEAR_TYPE(1..List_Size);
- Number : INTEGER := List_Size;
- end record;
-
- Data_Store : STUFF(5);
- Big_Store : STUFF(12);
- Var_Store : 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_Size loop
- Data_Store.Linear(Index1) := Index1;
- for Index2 in 1..Data_Store.List_Size loop
- Data_Store.Matrix(Index1,Index2) := Index1 * Index2;
- end loop;
- end loop;
-
- Var_Store := Data_Store;
- Put("The total of Var_Store is ");
- Put(Add_Elements(Var_Store));
- New_Line;
-
- Set_To_Ones(Var_Store);
- Put("The total of Var_Store is ");
- Put(Add_Elements(Var_Store));
- New_Line;
-
- Set_To_Ones(Big_Store);
- Var_Store := Big_Store;
- Put("The total of Var_Store is ");
- Put(Add_Elements(Var_Store));
- New_Line;
-
- end Discrim3;
-
-
-
-
- -- Result of execution
-
- -- The total of Var_Store is 225
- -- The total of Var_Store is 25
- -- The total of Var_Store is 144
-
-