Предположим, что в файле такого типа:
м
Иванов
123
80
ж
Петрова
185
54
...
Код
Type
Child=Record
Name:String;
Height:Integer;
Weight:Integer
End;
Var
m:Array[0..20] Of Child;
f:Array[0..20] Of Child;
mCount:Integer;
fCount:Integer;
df:Text;
s:String;
i,n,k:Integer;
b:Boolean;
Begin
Assign(f,'Children.Txt');
Reset(f);
mCount:=0;
fCount:=0;
While Not Eof (df) Do
Begin
ReadLn(f,s);
If (s='м') Or (s='М') Then
With m[mCount] Do
Begin
ReadLn(Name);
ReadLn(Height);
ReadLn(Weight);
Inc(mCount)
End
Else
With f[mCount] Do
Begin
ReadLn(Name);
ReadLn(Height);
ReadLn(Weight)
Inc(fCount)
End
End;
Close(df);
If (mCount=0) And (fCount=0) Then
Begin
WriteLn('There is no children')
Halt
End;
n:=0;
For i:=0 To mCount-1 Do
Inc(n,m[i].Weight);
WriteLn('Average Weight Of Boys: ',n/mCount:2:2);
n:=0;
For i:=0 To fCount-1 Do
Inc(n,f[i].Height);
WriteLn('Average Height Of Girls: ',n/fCount:2:2);
If (mCount>0) Then
Begin
n:=m[0].Height;
b:=True
End
Else
Begin
n:=f[0].Height;
b:=False
End;
k:=0;
For i:=0 To mCount-1 Do
If m[i].Height>n Then
Begin
k:=i;
n:=m[i].Height
End;
For i:=0 To fCount-1 Do
If f[i].Height>n Then
Begin
k:=i;
b:=False;
n:=f[i].Height
End;
Write('The highest is ');
If b Then
WriteLn(m[k].Name)
Else
WriteLn(f[k].Name);
WriteLn('The height is ',n)
End.
Примерно так...