Fill an array with record

FlamingClaw 0 Tallied Votes 212 Views Share

Often there is a case when we want to fill an array with record,and this program will demonstrate it...

(* fill in an array with record*)
Program PlayingWithRecords;

Uses Crt;
{we create a new type}
Type Pupil=Record
             Name:String[30];{first field string,that contains 30 char}
             BDate:1900..2009;
             Year:Byte;      {0..255}
           End;

Var TheClass:Array[1..30]Of Pupil;{This is a vektor array of pupil}
    Answer  :Pupil;               {this is a record type}
    i       :Byte;                {and this will be our little helper}

Begin{main}
  {we will fill the array with the studetnt's
  data,like:name,birthday,year}
  For i:=1 To 30 Do
     Begin
       {the question}
       Write('Give me the ',i:2,' student''s name: ');
       {the answer}
       ReadLn(Answer.Name);
       {put in the i.element}
       TheClass[i].Name:= Answer.Name;

       Write('Give me the ',i:2,' student''s birthday: ');
       ReadLn(Answer.BDate);
       TheClass[i].BDate:= Answer.BDate;

       Write('Give me the ',i:2,' student''s year: ');
       ReadLn(Answer.Year);
       TheClass[i].Year:= Answer.Year;
       WriteLn;
     End;{for}
     ReadKey;
End.{main}
{Created by FlamingClaw 2009.03.09}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.