home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog2 / adder2.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.4 KB  |  62 lines

  1.                                        -- Chapter 15 - Program 3
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Adder2 is
  6.  
  7.    package Flt_IO is new Text_IO.Float_IO(FLOAT);
  8.    use Flt_IO;
  9.  
  10.    FIRST : constant := 2;
  11.    LAST  : constant := 7;
  12.    Sum_Of_Values : FLOAT;
  13.  
  14.                       -- Interface of Package1
  15.    package AdderPkg is
  16.       type MY_ARRAY is array(INTEGER range <>) of FLOAT;
  17.       procedure Add_Em_Up(In_Dat : in     MY_ARRAY;
  18.                           Sum    :    out FLOAT);
  19.    end AdderPkg;
  20.  
  21.  
  22.    use Adder2.AdderPkg;
  23.    New_Array : MY_ARRAY(FIRST..LAST);
  24.  
  25.  
  26.                        -- Implementation of Package1
  27.    package body AdderPkg is
  28.       procedure Add_Em_Up(In_Dat : in     MY_ARRAY;
  29.                           Sum    :    out FLOAT) is
  30.       Total : FLOAT;
  31.       begin
  32.          Total := 0.0;
  33.          for Index in In_Dat'FIRST..In_Dat'LAST loop
  34.             Total := Total + In_Dat(Index);
  35.          end loop;
  36.          Sum := Total;
  37.       end Add_Em_Up;
  38.    end AdderPkg;
  39.  
  40.  
  41. begin
  42.    for Index in New_Array'FIRST..New_Array'LAST loop
  43.       New_Array(Index) := FLOAT(Index);
  44.    end loop;
  45.  
  46.    Put_Line("Call Add_Em_Up now.");
  47.    Add_Em_Up(New_Array,Sum_Of_Values);
  48.    Put("Back from Add_Em_Up, total is");
  49.    Put(Sum_Of_Values,5,2,0);
  50.    New_Line;
  51.  
  52. end Adder2;
  53.  
  54.  
  55.  
  56.  
  57. -- Result of execution
  58.  
  59. -- Call Add_Em_Up now
  60. -- Back from Add_Em_Up, total is   27.00
  61.  
  62.