Previous topic | Ada Home Page | Index

Arrays of Records

An array item may be of any type

Purpose:

Example

Result list for a sporting event:

    max_field : constant := 50;

    type Number is range 1 .. 1000;

    subtype String20 is String(1..20);

    type Time is digits 7 range 0.0 .. 600.0;

    type Competitor is record
        id_number : Number;
        name      : String20;
        club      : String20;
        run_time  : Time;
    end record;

   type Result_list is array (1 .. max_field) of Competitor;

   race1, race2 : Result_list;


Using Arrays of Records

Declarations

  1. constants: subtype limits, array sizes
  2. elementary types: subtypes, enumeration types, field types
  3. record data type
  4. array type: array of that record type
  5. array variables

Referring to portions of the array:

    race1(3).id_number := 23;

    get (race1(I).id_number);
 
    race1(J).name := "Joe Bloggs          ";

    PUT(race1(J).club);

    GET(race1(next).run_time);


Examples

Two example programs show the design and code of programs that involve arrays of records:


Previous topic | Ada Home Page | Index
c-lokan@adfa.oz.au / 27 Feb 96