Решите предыдущую задачу, не используя в программе массива записей. Подсказка: оператор Reset можно использовать в программе многократно для повторного чтения файла, начиная с его первой записи.
от

1 Ответ

program StudentsProcessingNoArray;
type   Student = record     LastName: string;     FirstName: string;     BirthYear: integer;     HeightCM: integer;     WeightKG: real;   end;
var   InputFile: text;   StudentData: Student;   TotalHeight, TotalWeight: real;   Count: integer;   AvgHeight, AvgWeight: real;   RostFile, VesFile: text;
begin   Assign(InputFile, 'students.txt');   Reset(InputFile);
  TotalHeight := 0;   TotalWeight := 0;   Count := 0;
  while not eof(InputFile) do   begin     read(InputFile, StudentData);     TotalHeight := TotalHeight + StudentData.HeightCM;     TotalWeight := TotalWeight + StudentData.WeightKG;     Count := Count + 1;   end;
  if Count > 0 then   begin     AvgHeight := TotalHeight / Count;     AvgWeight := TotalWeight / Count;   end   else   begin     AvgHeight := 0;     AvgWeight := 0;   end;
  writeln('Средний рост всех учеников: ', AvgHeight:0:2, ' см');   writeln('Средний вес всех учеников: ', AvgWeight:0:2, ' кг');
  Assign(RostFile, 'rost.txt');   Rewrite(RostFile);   Assign(VesFile, 'ves.txt');   Rewrite(VesFile);
  Reset(InputFile);
  while not eof(InputFile) do   begin     read(InputFile, StudentData);     if StudentData.HeightCM > AvgHeight then       writeln(RostFile, StudentData.LastName, ' ', StudentData.FirstName, ' ', StudentData.BirthYear);     if StudentData.WeightKG < AvgWeight then       writeln(VesFile, StudentData.LastName, ' ', StudentData.FirstName, ' ', StudentData.BirthYear);   end;
  Close(InputFile);   Close(RostFile);   Close(VesFile); end.
от