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

  1.                                        -- Chapter 8 - Program 8
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Overload is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    Int_Dat : INTEGER;
  11.    Flt_Dat : FLOAT;
  12.  
  13.  
  14.    function Raise_To_Power(Index : INTEGER) return INTEGER is
  15.    begin
  16.       Put_Line("In the INTEGER function.");
  17.       return Index * Index;
  18.    end Raise_To_Power;
  19.  
  20.  
  21.  
  22.    function Raise_To_Power(Value : FLOAT) return FLOAT is
  23.    begin
  24.       Put_Line("In the FLOAT function.");
  25.       return Value * Value * Value;
  26.    end Raise_To_Power;
  27.  
  28.  
  29.  
  30.    procedure Raise_To_Power(Index  : in     INTEGER;
  31.                             Result :    out INTEGER) is
  32.    begin
  33.       Put_Line("In the INTEGER procedure.");
  34.       Result := Index * Index * Index;
  35.    end Raise_To_Power;
  36.  
  37.  
  38.  
  39.    procedure Raise_To_Power(Value  : in     FLOAT;
  40.                             Result :    out FLOAT) is
  41.    begin
  42.       Put_Line("In the FLOAT procedure.");
  43.       Result := Value * Value;
  44.    end Raise_To_Power;
  45.  
  46. begin
  47.  
  48.    Int_Dat := Raise_To_Power(2);     -- uses INTEGER function
  49.  
  50.    Flt_Dat := Raise_To_Power(3.2);   -- uses FLOAT function
  51.  
  52.    Raise_To_Power(3,Int_Dat);        -- uses INTEGER procedure
  53.  
  54.    Raise_To_Power(2.73,Flt_Dat);     -- uses FLOAT procedure
  55.  
  56.    Int_Dat := 2;
  57.                       -- In the following statement,
  58.                       -- the function returns 2 squared, or 4
  59.                       -- and the procedure cubes it to 64.
  60.    Raise_To_Power(Raise_To_Power(Int_Dat),Int_Dat);
  61.    Put("The result is ");
  62.    Put(Int_Dat);
  63.    New_Line;
  64.  
  65. end Overload;
  66.  
  67.  
  68.  
  69.  
  70. -- Result of execution
  71.  
  72. -- In the INTEGER function.
  73. -- In the FLOAT function.
  74. -- In the INTEGER procedure.
  75. -- In the FLOAT procedure.
  76. -- In the INTEGER function.
  77. -- In the INTEGER procedure.
  78. -- The result is     64
  79.  
  80.