home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 15 - Program 6
-
- -- Interface of AdderPkg
- package AdderPkg is
- Total : FLOAT; -- Global variable
- type MY_ARRAY is array(INTEGER range <>) of FLOAT;
- procedure Add_Em_Up(In_Dat : in MY_ARRAY;
- Sum : out FLOAT);
- end AdderPkg;
-
-
- -- Implementation of AdderPkg
- package body AdderPkg is
- procedure Add_Em_Up(In_Dat : in MY_ARRAY;
- Sum : out FLOAT) is
- begin
- for Index in In_Dat'FIRST..In_Dat'LAST loop
- Total := Total + In_Dat(Index);
- end loop;
- Sum := Total;
- end Add_Em_Up;
-
- begin -- Initialization section
- Total := 0.0;
- end AdderPkg;
-
-
-
-
- with Text_IO;
- use Text_IO;
-
- with AdderPkg;
- use AdderPkg;
-
- procedure Adder4 is
-
- package Flt_IO is new Text_IO.Float_IO(FLOAT);
- use Flt_IO;
-
- FIRST : constant := 2;
- LAST : constant := 7;
- Sum_Of_Values : FLOAT;
-
- New_Array : MY_ARRAY(FIRST..LAST);
-
- procedure Summer(In_Dat : MY_ARRAY;
- Sum : out FLOAT) renames AdderPkg.Add_Em_Up;
- begin
- for Index in New_Array'FIRST..New_Array'LAST loop
- New_Array(Index) := FLOAT(Index);
- end loop;
-
- Put_Line("Call Add_Em_Up now.");
- Add_Em_Up(New_Array,Sum_Of_Values);
- Put("Back from Add_Em_Up, total is");
- Put(Sum_Of_Values,5,2,0);
- New_Line;
-
- -- The next three statements are identical
- Add_Em_Up(New_Array,Sum_Of_Values);
- AdderPkg.Add_Em_Up(New_Array,Sum_Of_Values);
- Summer(New_Array,Sum_Of_Values);
-
- end Adder4;
-
-
-
-
- -- Result of execution
-
- -- Call Add_Em_Up now
- -- Back from Add_Em_Up, total is 27.00
-