home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 20 - Programming exercise 1
- with Text_IO;
- use Text_IO;
-
- procedure CH20_1 is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- type POWER is (GAS, STEAM, DIESEL, NONE);
-
- package Enum_IO is new Text_IO.Enumeration_IO(POWER);
- use Enum_IO;
-
- type VEHICLE (Engine : POWER) is
- record
- Model_Year : INTEGER range 1888..1992;
- Wheels : INTEGER range 2..18;
- case Engine is
- when GAS => Cylinders : INTEGER range 1..16;
- when STEAM => Boiler_Size : INTEGER range 5..22;
- Coal_Burner : BOOLEAN;
- when DIESEL => Fuel_Inject : BOOLEAN;
- when NONE => Speeds : INTEGER range 1..15;
- end case;
- end record;
-
- Ford : VEHICLE(GAS);
- Truck : VEHICLE(DIESEL);
- Schwinn : VEHICLE(NONE);
- Stanley : VEHICLE(STEAM);
-
- begin
-
- Ford.Model_Year := 1956; -- Component assignment
- Ford.Wheels := 4;
- Ford.Cylinders := 8;
-
- Ford := (GAS, 1956, 4, 8); -- Positional aggregate assignment
-
- -- Named aggregate assignment
- Ford := (Model_Year => 1956, Cylinders => 8, Engine => GAS,
- Wheels => 4);
-
- Stanley.Model_Year := 1908;
- Stanley.Wheels := 4;
- Stanley.Boiler_Size := 21;
- Stanley.Coal_Burner := FALSE;
- -- Mixed aggregate assignment
- Stanley := (STEAM, 1908, 4, Coal_Burner => FALSE,
- Boiler_Size => 21);
-
- Schwinn.Speeds := 10;
- Schwinn.Wheels := 2;
- Schwinn.Model_Year := 1985;
-
- Truck.Model_Year := 1966;
- Truck.Wheels := 18;
- Truck.Fuel_Inject := TRUE;
-
- Put("Stanley engine type is ");
- Put(Stanley.Engine);
- Put(", and has");
- Put(Stanley.Wheels,3);
- Put_Line(" wheels.");
-
- Put("The truck is a");
- Put(Truck.Model_Year,5);
- Put(" and has");
- Put(Truck.Wheels,3);
- Put_Line(" wheels.");
-
- end CH20_1;
-
-
-
-
- -- Result of Execution
-
- -- Stanley engine type is STEAM, and has 4 wheels.
- -- The truck is a 1966 and has 18 wheels.
-
-