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

  1.                                        -- Chapter 20 - Program 5
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Variant1 is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type POWER is (GAS, STEAM, DIESEL, NONE);
  11.  
  12.    type VEHICLE (Engine : POWER) is
  13.       record
  14.          Model_Year : INTEGER range 1888..1992;
  15.          Wheels     : INTEGER range 2..18;
  16.          case Engine is
  17.             when GAS    => Cylinders   : INTEGER range 1..16;
  18.             when STEAM  => Boiler_Size : INTEGER range 5..22;
  19.                            Coal_Burner : BOOLEAN;
  20.             when DIESEL => Fuel_Inject : BOOLEAN;
  21.             when NONE   => Speeds      : INTEGER range 1..15;
  22.          end case;
  23.       end record;
  24.  
  25.    Ford    : VEHICLE(GAS);
  26.    Truck   : VEHICLE(DIESEL);
  27.    Schwinn : VEHICLE(NONE);
  28.    Stanley : VEHICLE(STEAM);
  29.  
  30. begin
  31.  
  32.    Ford.Model_Year := 1956;       -- Component assignment
  33.    Ford.Wheels := 4;
  34.    Ford.Cylinders := 8;
  35.  
  36.    Ford := (GAS, 1956, 4, 8);     -- Positional aggregate assignment
  37.  
  38.                                   -- Named aggregate assignment
  39.    Ford := (Model_Year => 1956, Cylinders => 8, Engine => GAS,
  40.                                                       Wheels => 4);
  41.  
  42.    Stanley.Model_Year := 1908;
  43.    Stanley.Wheels := 4;
  44.    Stanley.Boiler_Size := 21;
  45.    Stanley.Coal_Burner := FALSE;
  46.                                   -- Mixed aggregate assignment
  47.    Stanley := (STEAM, 1908, 4, Coal_Burner => FALSE,
  48.                                                 Boiler_Size => 21);
  49.  
  50.    Schwinn.Speeds := 10;
  51.    Schwinn.Wheels := 2;
  52.    Schwinn.Model_Year := 1985;
  53.  
  54.    Truck.Model_Year := 1966;
  55.    Truck.Wheels := 18;
  56.    Truck.Fuel_Inject := TRUE;
  57.  
  58. end Variant1;
  59.  
  60.  
  61.  
  62.  
  63. -- Result of Execution
  64.  
  65. --    (No results are output.)
  66.  
  67.