comp.lang.ada
 help / color / mirror / Atom feed
From: R Mullen <rmullen@mcmail.com>
Subject: an array of records within an array of records
Date: 1998/04/14
Date: 1998-04-14T00:00:00+00:00	[thread overview]
Message-ID: <3533A214.D5F94451@mcmail.com> (raw)


I am trying to create a jukebox program, and part of it involves having
an array of records for the cd, and within
that cd array have an array of records for the cd track. Firstly
displaying each cd and having the user choose a
cd, then displaying all tracks for that particular cd. I have
encountered two problems so far

1. I cant supply an index to the record array of cd tracks only the
index to the cd's, I am using the syntax of

    put(new_cd_array(index).track(loop_index).title);

index, being the index passed to the procedure the code is in,
representing the cd selected, and loop-index
representing a loop, to loop round displaying all the fields in the
tracks record array. Which I thought would work,
however it refuses to operate correctly. And now I have removed it from
the program I cant tell you what errors it
was displaying. I have also tried every variation as well, but I still
cant make it work.

2. Also how do you pre initialise the tracks array of records, the only
way I could think of is:

new_cd_array(1):=("title1--------------","artist1-------------",("title1--------------","artist1-------------",12.34,1),1);

new_cd_array(1):=("title1--------------","artist1-------------",("title2--------------","artist2-------------",12.34,2),1);

new_cd_array(1):=("title1--------------","artist1-------------",("title3--------------","artist3-------------",12.34,3),1);

Surely this is a long-winded way, isn't there something easier?

I don't want to be spoon fed the answers, but some helpful advice would
be nice.

Thanks R Mullen

---------------------------------------------

I have also included the record initialisation in the declarations
section as well as some of the program code:

Declaration section:


          type cd_track is
          record
                  title:string(1..20);
                  artist:string(1..20);
                  playlength:float:=0.00;
                  id:integer;
          end record;

  type cd_track_array is array(positive range<>) of cd_track;
  new_cd_track:cd_track_array(1..3);

          type cd is
          record
                  title:string(1..20);
                  artist:string(1..20);
                  id:cd_track;
                  tracks:integer;
          end record;

  type cd_array is array(positive range<>) of cd;
  new_cd_array:cd_array(1..3);


main program:


  procedure individual_cd(index:in integer) is
          begin
            for loop_index in 1..3 loop
                    put(new_cd_array(index).title);

                    put(new_cd_array(index).track(loop_index).title);

                    put(new_cd_array(index).artist);
                    put(new_cd_array(index).playlength);
                    put(new_cd_array(index).id);
            end loop;
                    put_line("  ");
                    put_line("Select a track by choosing its ID.");
                    put_line("  ");


            end individual_cd;



  Text IO and Float IO are both in use, and I am using the latest
version of the GNAT compiler.





             reply	other threads:[~1998-04-14  0:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-04-14  0:00 R Mullen [this message]
1998-04-15  0:00 ` an array of records within an array of records Michael F Brenner
1998-04-15  0:00   ` Matthew Heaney
1998-04-16  0:00     ` Tom Moran
1998-04-16  0:00       ` Matthew Heaney
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox