-- Chapter 31 - Program 3 generic type ITEM is range <>; ROWS : in POSITIVE := 8; COLUMNS : in POSITIVE := 12; package Matrix_Operations is type LOCAL_MATRIX is private; procedure Clear_Matrix(Matrix_To_Clear : in out LOCAL_MATRIX); function Add_Matrices(M1, M2 : LOCAL_MATRIX) return LOCAL_MATRIX; private type LOCAL_MATRIX is array(POSITIVE range 1..ROWS, POSITIVE range 1..COLUMNS) of ITEM; end Matrix_Operations; with Ada.Text_IO; use Ada.Text_IO; package body Matrix_Operations is procedure Clear_Matrix(Matrix_To_Clear : in out LOCAL_MATRIX) is begin for Row in 1..Matrix_To_Clear'LAST(1) loop for column in 1.. Matrix_To_Clear'LAST(2) loop Matrix_To_Clear(Row,Column) := 0; end loop; end loop; Put_Line(" A matrix has been cleared"); end Clear_Matrix; function Add_Matrices(M1, M2 : LOCAL_MATRIX) return LOCAL_MATRIX is Temp : LOCAL_MATRIX; begin for Row in 1..M1'LAST(1) loop for column in 1.. M1'LAST(2) loop Temp(Row, Column) := M1(Row, Column) + M2(Row, Column); end loop; end loop; Put_Line(" Two matrices have been summed"); return Temp; end Add_Matrices; end Matrix_Operations; with Ada.Text_IO, Matrix_Operations; use Ada.Text_IO; procedure ObjGen is package Cookie_Jar is new Matrix_Operations(NATURAL, 3, 5); use Cookie_Jar; package Puppies is new Matrix_Operations(INTEGER); package Animals is new Matrix_Operations(COLUMNS => 7, ROWS => 11, ITEM => INTEGER); use Animals; Cookie_Matrix : Cookie_Jar.LOCAL_MATRIX; Dog_Matrix : Puppies.LOCAL_MATRIX; Cattle, Jerseys, Black_Angus : Animals.LOCAL_MATRIX; begin Put_Line("Begin the matrix operations."); Clear_Matrix(Cookie_Matrix); Puppies.Clear_Matrix(Dog_Matrix); Clear_Matrix(Jerseys); Clear_Matrix(Black_Angus); Cattle := Add_Matrices(Jerseys, Black_Angus); end ObjGen; -- Result of execution -- Begin the matrix operations -- A matrix has been cleared -- A matrix has been cleared -- A matrix has been cleared -- A matrix has been cleared -- Two matrices have been summed