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

  1.                                    -- Chapter 25 - Program 3
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure ManyDogs is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    task Gourmet is
  11.       entry Make_A_Hot_Dog(Serial_Number : INTEGER;
  12.                            With_Mustard  : BOOLEAN);
  13.    end Gourmet;
  14.  
  15.    task body Gourmet is
  16.    begin
  17.       Put_Line("I am ready to make a hot dog for you");
  18.       for Index in 1..5 loop
  19.          accept Make_A_Hot_Dog(Serial_Number : INTEGER;
  20.                                With_Mustard  : BOOLEAN) do
  21.             Put("Put hot dog number");
  22.             Put(Serial_Number,3);
  23.             Put(" in bun ");
  24.             if With_Mustard then
  25.                Put_Line("and add mustard");
  26.             else
  27.                Put_Line("and hold the mustard");
  28.             end if;
  29.             delay 0.8;
  30.          end Make_A_Hot_Dog;
  31.       end loop;
  32.       Put_Line("I am out of hot dogs");
  33.    end Gourmet;
  34.  
  35.    task Bill;
  36.    task John;
  37.  
  38.    task body Bill is
  39.    begin
  40.       for Index in 1..3 loop
  41.          Gourmet.Make_A_Hot_Dog(Index,FALSE);
  42.          Put_Line("Bill is eating the hot dog without mustard");
  43.          New_Line;
  44.       end loop;
  45.       Put_Line("Bill is not hungry any longer");
  46.    end Bill;
  47.  
  48.    task body John is
  49.    begin
  50.       for Index in 1..2 loop
  51.          Gourmet.Make_A_Hot_Dog(Index,TRUE);
  52.          Put_Line("John is eating the hot dog with mustard");
  53.          New_Line;
  54.       end loop;
  55.       Put_Line("John is not hungry any longer");
  56.    end John;
  57.  
  58. begin
  59.    null;
  60. end ManyDogs;
  61.  
  62.  
  63. -- Result of execution
  64.  
  65. -- I am ready to make a hot dog for you
  66. -- Put hot dog number 1 in bun and add mustard
  67. -- Put hot dog number 1 in bun and hold the mustard
  68. -- John is eating the hot dog with mustard
  69. --
  70. -- Put hot dog number 2 in bun and add mustard
  71. -- Bill is eating the hot dog without mustard
  72. --
  73. -- Put hot dog number 2 in bun and hold the mustard
  74. -- John is eating the hot dog with mustard
  75. --
  76. -- John is not hungry any longer
  77. -- Bill is eating the hot dog without mustard
  78. --
  79. -- Put hot dog number 3 in bun and hold the mustard
  80. -- I am out of hot dogs
  81. -- Bill is eating the hot dog without mustard
  82. --
  83. -- Bill is not hungry any longer
  84.  
  85.