comp.lang.ada
 help / color / mirror / Atom feed
* an array of records within an array of records
@ 1998-04-14  0:00 R Mullen
  1998-04-15  0:00 ` Michael F Brenner
  0 siblings, 1 reply; 5+ messages in thread
From: R Mullen @ 1998-04-14  0:00 UTC (permalink / 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.





^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: an array of records within an array of records
  1998-04-14  0:00 an array of records within an array of records R Mullen
@ 1998-04-15  0:00 ` Michael F Brenner
  1998-04-15  0:00   ` Matthew Heaney
  0 siblings, 1 reply; 5+ messages in thread
From: Michael F Brenner @ 1998-04-15  0:00 UTC (permalink / raw)



Yes, record initialization is a little long-winded, and is even
more so when you make it more readable by adding in the field names:
  
  x := (CD=> 190, title => to_20 ("White Album"), author => to_20("Beatles"));

Although it is long-winded, giving the field names can be very helpful
if you come back to the data years later and wonder what is being
filled in. 

It also helps when you are trying to pick out which of hundreds of data
files is the input file for the juke box, as opposed to the financial
program, the business process model, or the satellite location program.






^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: an array of records within an array of records
  1998-04-15  0:00 ` Michael F Brenner
@ 1998-04-15  0:00   ` Matthew Heaney
  1998-04-16  0:00     ` Tom Moran
  0 siblings, 1 reply; 5+ messages in thread
From: Matthew Heaney @ 1998-04-15  0:00 UTC (permalink / raw)



In article <6h307q$5qj@top.mitre.org>, mfb@mbunix.mitre.org (Michael F
Brenner) wrote:

>Yes, record initialization is a little long-winded, and is even
>more so when you make it more readable by adding in the field names:
>  
>  x := (CD=> 190, title => to_20 ("White Album"), author => to_20("Beatles"));
>
>Although it is long-winded, giving the field names can be very helpful
>if you come back to the data years later and wonder what is being
>filled in. 

Here's a case where using the identity operator as a constructor can
improve things:

x := (CD => 190, title => +"White Album", author => +"Beatles");

In general, when you have a subprogram (or record type) that has parameters
(components) of the same type (as you do here, with type String), then it's
safer to use named notation, so you don't accidently assign the wrong
value.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: an array of records within an array of records
  1998-04-15  0:00   ` Matthew Heaney
@ 1998-04-16  0:00     ` Tom Moran
  1998-04-16  0:00       ` Matthew Heaney
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Moran @ 1998-04-16  0:00 UTC (permalink / raw)



> identity operator
What's that in this case?  The operator that maps type String to
whatever other type to_20 maps strings to?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: an array of records within an array of records
  1998-04-16  0:00     ` Tom Moran
@ 1998-04-16  0:00       ` Matthew Heaney
  0 siblings, 0 replies; 5+ messages in thread
From: Matthew Heaney @ 1998-04-16  0:00 UTC (permalink / raw)



In article <353579d7.34211077@SantaClara01.news.InterNex.Net>,
tmoran@bix.com (Tom Moran) wrote:

>> identity operator
>What's that in this case?  The operator that maps type String to
>whatever other type to_20 maps strings to?

Yes:

function "+" (R : String) return <some type>  renames To_20;




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-04-16  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-04-14  0:00 an array of records within an array of records R Mullen
1998-04-15  0:00 ` Michael F Brenner
1998-04-15  0:00   ` Matthew Heaney
1998-04-16  0:00     ` Tom Moran
1998-04-16  0:00       ` Matthew Heaney

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