The Ada Program: sort-get_data.adb

  1 -- sort-get_data.adb:  get employee records from data file
  2 
  3 separate (Sort)
  4 
  5 procedure Get_Data (File_Name        : in String;
  6                     List             : out List_Type;
  7                     Number_Of_Records: out Natural) is
  8 
  9    Data_File : Text_IO.File_Type;
 10 
 11    procedure Get_Record (R: out Employee_Record) is
 12    begin
 13 
 14       Text_IO.Get (Data_File, R.Name);
 15       Integer_Text_IO.Get (Data_File, R.ID);
 16       Integer_Text_IO.Get (Data_File, R.Salary);
 17       Integer_Text_IO.Get (Data_File, R.Department);
 18 
 19    end Get_Record;
 20 
 21 begin
 22 
 23    Text_IO.Open (File=>Data_File,Name=>File_Name,Mode=>Text_IO.In_File);
 24 
 25    Number_Of_Records := 0;
 26 
 27    while (not Text_IO.End_Of_File (Data_File)) loop
 28       Number_Of_Records := Number_Of_Records + 1;
 29       List (Number_Of_Records) := new Employee_Record;
 30       Get_Record (List(Number_Of_Records).all);
 31       Text_IO.Skip_Line (Data_File);
 32    end loop;
 33 
 34    Text_IO.Close (Data_File);
 35 
 36 end Get_Data;