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

  1.                                        -- Chapter 18 - Program 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Defaults 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.    procedure Animals(Total : in out INTEGER;
  14.                      Cows  : in     INTEGER := 0;
  15.                      Pigs  : in     INTEGER := 0;
  16.                      Dogs  : in     INTEGER := 0) is
  17.    begin
  18.       Total := Cows + Pigs + Dogs;
  19.       Put("Cows =");
  20.       Put(Cows,3);
  21.       Put("   Pigs =");
  22.       Put(Pigs,3);
  23.       Put("   Dogs =");
  24.       Put(Dogs,3);
  25.       Put("   and they total");
  26.       Put(Total,4);
  27.       New_Line;
  28.    end Animals;
  29.  
  30. begin
  31.    Index := 3;
  32.    Animals(Animal_Sum,2,3,4);
  33.    Animals(Animal_Sum,2,Index,4);
  34.    Animals(Dogs => 4,Total => Animal_Sum);
  35.    Animals(Total => Animal_Sum,Pigs => 2*Index + 1,Cows => 5);
  36.    Animals(Dogs => Index + 4,Total => Animal_Sum);
  37.    Animals(Animal_Sum,Dogs => 4,Pigs => Index,Cows => 2);
  38.    Animals(Animal_Sum);
  39. end Defaults;
  40.  
  41.  
  42.  
  43.  
  44. -- Result of Execution
  45.  
  46. -- Cows =  2   Pigs =  3   Dogs =  4   and they total   9
  47. -- Cows =  2   Pigs =  3   Dogs =  4   and they total   9
  48. -- Cows =  0   Pigs =  0   Dogs =  4   and they total   4
  49. -- Cows =  5   Pigs =  7   Dogs =  0   and they total  12
  50. -- Cows =  0   Pigs =  0   Dogs =  7   and they total   7
  51. -- Cows =  2   Pigs =  3   Dogs =  4   and they total   9
  52. -- Cows =  0   Pigs =  0   Dogs =  0   and they total   0
  53.  
  54.