HOMEWORK PROBLEM 5 INTRODUCTION TO Ada I 586.1 PURPOSE: To learn about matrices and overloaded operators. To specify types and exceptions in a utility library package END RESULT: A complete Ada program that is a main procedure that WITH's a package you modify. PROBLEM: Modify the attached package Real_Matrix_Arithmetic , a skeleton for a complete real matrix arithmetic package. Use the matrix multiply "*" as a guide to write matrix add "+". Keep the matrix multiply and use both in the main procedure. The only requirement for matrix add is that A'Length(1) = B'Length(1) and A'Length(2) = B'Length(2). TURN IN: Printout of main procedure and package. Printout of execution for test data. ( modify to suit your needs. Matrices as small as 3 by 2 are acceptable , not square matrices) OBSERVE: The type Real_Matrix is defined in the package and is visible in the main procedure because of the "with" and "use" on Real_Matrix_Arithmetic. The objects MAT_1 etc. are declared and assigned storage in the main procedure. The object C is dynamically assigned storage with a size that depends on the formal parameter A when "*" is called. The user defined exception Matrix_Error is defined and may be raised in the package. This exception may then be handled as the user desires in the main procedure. This avoids the need for math routines to print out errors and allows the calling procedure to take corrective action for some types of errors. Be sure to handle first and second subscript ranges having different first subscripts. Only the length of the side of the matrix is important. EXTRA Add tests to make sure all cases work. READING: BARNES 9.1 9.2 9.3 A1.2 ISO 8652:1995 6.1 6.2 6.3 6.4 Annex K LECTURE: will also cover attributes in Annex K QUIZ NEXT SESSION The following are some convenient packages to have compiled. Int_IO.ads with Ada.Text_IO ; package Int_IO is new Ada.Text_IO.Integer_IO ( Integer ) ; NOTE: compiling the above package may allow faster compilation of later units. Replace "package Int_IO is new Integer_IO ( Integer ) ; use Int_IO ;" with "with Int_IO ; use Int_IO ;" before the package or procedure Define_Real.ads -- This package provides the definition of the type Real and Long_Real. -- For computers with only one floating point hardware both subtypes -- become the same. package Define_Real is subtype Real is Float ; -- may be Short_Float subtype Long_Real is Long_Float ; -- may be Float end Define_Real ; Real_IO.ads with Define_Real ; with Ada.Text_IO ; package Real_IO is new Ada.Text_IO.Float_IO ( Define_Real.Real ) ; Note: As projects get larger, there is more importance on not changing package specifications. This has two ramifications. First put the package specification in one file and the package body in another. (.ads and .ads for gnat) Second, only put "with" statements on the specification that are needed by the specification. The body typically needs more "with" statements. This speeds up compilations and reduces dependencies. More stray information : The VAX VMS naming convention for files containing package specifications is to add an underscore to the package name in order to get the file name. The package body file name is the same as the package name. The gnat naming convention is to use the package name with extensions .ads for specifications and .adb for bodies.