home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 8 - Programming exercise 3
- with Text_IO;
- use Text_IO;
-
- procedure CH08_3 is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- Int_Dat : INTEGER;
- Flt_Dat : FLOAT;
-
-
- function Raise_To_Power(Index : INTEGER) return INTEGER is
- begin
- Put_Line("In the INTEGER function.");
- return Index * Index;
- end Raise_To_Power;
-
-
-
- function Raise_To_Power(Value : FLOAT) return FLOAT is
- begin
- Put_Line("In the FLOAT function.");
- return Value * Value * Value;
- end Raise_To_Power;
-
-
-
- function Raise_To_Power(Value : INTEGER) return FLOAT is
- begin
- Put_Line("In the new function.");
- return FLOAT(Value * Value * Value);
- end Raise_To_Power;
-
-
-
- procedure Raise_To_Power(Index : in INTEGER;
- Result : out INTEGER) is
- begin
- Put_Line("In the INTEGER procedure.");
- Result := Index * Index * Index;
- end Raise_To_Power;
-
-
-
- procedure Raise_To_Power(Value : in FLOAT;
- Result : out FLOAT) is
- begin
- Put_Line("In the FLOAT procedure.");
- Result := Value * Value;
- end Raise_To_Power;
-
- begin
-
- Int_Dat := Raise_To_Power(2); -- uses INTEGER function
-
- Flt_Dat := Raise_To_Power(3); -- uses new function
-
- Raise_To_Power(3,Int_Dat); -- uses INTEGER procedure
-
- Raise_To_Power(2.73,Flt_Dat); -- uses FLOAT procedure
-
- Int_Dat := 2;
- -- In the following statement,
- -- the function returns 2 squared, or 4
- -- and the procedure cubes it to 64.
- Raise_To_Power(Raise_To_Power(Int_Dat),Int_Dat);
- Put("The result is ");
- Put(Int_Dat);
- New_Line;
-
- end CH08_3;
-
-
-
-
- -- Result of execution
-
- -- In the INTEGER function.
- -- In the new function.
- -- In the INTEGER procedure.
- -- In the FLOAT procedure.
- -- In the INTEGER function.
- -- In the INTEGER procedure.
- -- The result is 64
-
-