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

  1.                                        -- Chapter 18 - Program 2
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Default2 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10. Index      : INTEGER;
  11. Animal_Sum : INTEGER;
  12.  
  13.    function Cow_Constant return INTEGER is
  14.    begin
  15.       return 7;
  16.    end Cow_Constant;
  17.  
  18.    function Pig_Constant return INTEGER is
  19.    Animals : INTEGER := Cow_Constant - 3;
  20.    begin
  21.       return 2 * Animals + 5;
  22.    end Pig_Constant;
  23.  
  24.    procedure Animals(Total : in out INTEGER;
  25.                      Cows  : in     INTEGER := 2 * Cow_Constant;
  26.                      Pigs  : in     INTEGER := Cow_Constant +
  27.                                                Pig_Constant;
  28.                      Dogs  : in     INTEGER := 0) is
  29.    begin
  30.       Total := Cows + Pigs + Dogs;
  31.       Put("Cows =");
  32.       Put(Cows,3);
  33.       Put("   Pigs =");
  34.       Put(Pigs,3);
  35.       Put("   Dogs =");
  36.       Put(Dogs,3);
  37.       Put("   and they total");
  38.       Put(Total,4);
  39.       New_Line;
  40.    end Animals;
  41.  
  42. begin
  43.    Index := 3;
  44.    Animals(Animal_Sum,2,3,4);
  45.    Animals(Animal_Sum,2,Index,4);
  46.    Animals(Dogs => 4,Total => Animal_Sum);
  47.    Animals(Total => Animal_Sum,Pigs => 2*Index + 1,Cows => 5);
  48.    Animals(Dogs => Index + 4,Total => Animal_Sum);
  49.    Animals(Animal_Sum,Dogs => 4,Pigs => Index,Cows => 2);
  50.    Animals(Animal_Sum);
  51. end Default2;
  52.  
  53.  
  54.  
  55.  
  56. -- Result of Execution
  57.  
  58. -- Cows =  2   Pigs =  3   Dogs =  4   and they total   9
  59. -- Cows =  2   Pigs =  3   Dogs =  4   and they total   9
  60. -- Cows = 14   Pigs = 20   Dogs =  4   and they total  38
  61. -- Cows =  5   Pigs =  7   Dogs =  0   and they total  12
  62. -- Cows = 14   Pigs = 20   Dogs =  7   and they total  41
  63. -- Cows =  2   Pigs =  3   Dogs =  4   and they total   9
  64. -- Cows = 14   Pigs = 20   Dogs =  0   and they total  34
  65.  
  66.