The Ada Program: cd.adb

  1 -- cd.adb: using pointers to arrays and strings to represent audio CD info
  2 
  3 with Ada.Text_IO;
  4 use Ada;
  5 
  6 procedure CD is
  7 
  8    type String_Pointer is access String;
  9    type Tracks_Type is array (Positive range <>) of String_Pointer;
 10    type Tracks_Pointer is access Tracks_Type;
 11    subtype Year_Range is Integer range 1900..2990;
 12 
 13 
 14    type Disc is record
 15       Artist, Album: String_Pointer;
 16       Year: Year_Range;
 17       Tracks: Tracks_Pointer;
 18    end record;
 19 
 20    function New_Disk (Artist,Album: String; Y: Year_Range; Tracks: Tracks_Type) return Disc is
 21    begin
 22       return Disc' (
 23          Artist=>new String' (Artist),
 24          Album=>new String' (Album),
 25          Year=>Y,
 26          Tracks=>new Tracks_Type' (Tracks)
 27       );
 28    end New_Disk;
 29 
 30    CD1, CD2: Disc;
 31 
 32 begin
 33 
 34    CD1 := Disc'(
 35       Artist=>new String' ("Bob Dylan"),
 36       Album =>new String' ("Freewheelin'"),
 37       Year  =>1963,
 38       Tracks=>new Tracks_Type' (
 39          01=>new String' ("Blowin' in The Wind"),
 40          02=>new String' ("Girl From The North Country"),
 41          03=>new String' ("Masters of War"),
 42          04=>new String' ("Down The Highway"),
 43          05=>new String' ("Bob Dylan's Blues"),
 44          06=>new String' ("A Hard Rain's A-Gonna Fall"),
 45          07=>new String' ("Don't Think Twice, It's all Right"),
 46          08=>new String' ("Bob Dylan's Dream"),
 47          09=>new String' ("Oxford Town"),
 48          10=>new String' ("Talking World War III Blues"),
 49          11=>new String' ("Corrina, Corrina"),
 50          12=>new String' ("Honey, Just Allow Me One More Chance"),
 51          13=>new String' ("I Shall Be Free")
 52       )
 53    );
 54 
 55    CD2 := New_Disk ("Bob Dylan", "Highway 61 Revisited", 1965,
 56       Tracks=>Tracks_Type' (
 57          01=>new String' ("Like A Rolling Stone"),
 58          02=>new String' ("Tombstone Blues"),
 59          03=>new String' ("It Takes A Lot To Laugh, It Takes A Train To Cry"),
 60          04=>new String' ("From A Buick 6"),
 61          05=>new String' ("Ballad of A Thin Man"),
 62          06=>new String' ("Queen Jane Approximately"),
 63          07=>new String' ("Highway 61 Revisited"),
 64          08=>new String' ("Just Like Tom Thumb's Blues"),
 65          09=>new String' ("Desolation Row")
 66       )
 67    );
 68 
 69    if CD1.Artist=CD2.Artist then
 70       Text_IO.Put_Line ("Yes");
 71    else
 72       Text_IO.Put_Line ("No");
 73    end if;
 74 
 75 end CD;