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

  1.                                     -- Chapter 25 - Program 4
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Retail1 is
  6.  
  7.    Number_Of_Dogs : INTEGER := 0;
  8.  
  9.    task Retail_Hot_Dogs is
  10.       entry Stock_With_A_Hot_Dog;
  11.       entry Deliver_A_Hot_Dog;
  12.    end Retail_Hot_Dogs;
  13.  
  14.    task body Retail_Hot_Dogs is
  15.    begin
  16.       accept Stock_With_A_Hot_Dog do
  17.          Put_Line("Put the first hot dog on the shelf");
  18.          Number_Of_Dogs := Number_Of_Dogs + 1;
  19.       end Stock_With_A_Hot_Dog;
  20.  
  21.       for Index in 1..7 loop
  22.          Put("In loop => ");
  23.          select
  24.             accept Stock_With_A_Hot_Dog do
  25.                Put_Line("Add a hot dog to the shelf");
  26.                Number_Of_Dogs := Number_Of_Dogs + 1;
  27.             end Stock_With_A_Hot_Dog;
  28.          or
  29.             accept Deliver_A_Hot_Dog do
  30.                Put_Line("Remove a hot dog from the shelf");
  31.                Number_Of_Dogs := Number_Of_Dogs - 1;
  32.             end Deliver_A_Hot_Dog;
  33.          end select;
  34.       end loop;
  35.    end Retail_Hot_Dogs;
  36.  
  37. begin
  38.    for Index in 1..4 loop
  39.       Retail_Hot_Dogs.Stock_With_A_Hot_Dog;
  40.       Retail_Hot_Dogs.Deliver_A_Hot_Dog;
  41.    end loop;
  42. end Retail1;
  43.  
  44.  
  45.  
  46.  
  47. -- Result of execution
  48.  
  49. -- Put the first hot dog on the shelf
  50. -- In loop => Remove a hot dog from the shelf
  51. -- In loop => Add a hot dog to the shelf
  52. -- In loop => Remove a hot dog from the shelf
  53. -- In loop => Add a hot dog to the shelf
  54. -- In loop => Remove a hot dog from the shelf
  55. -- In loop => Add a hot dog to the shelf
  56. -- In loop => Remove a hot dog from the shelf
  57.  
  58.