type TPosition = (_goalkeeper, _defender, _midfielder, _forward); TPeople = object age: integer; name: string; constructor init(AName: string; AnAge: integer); end; PTFootballer = ^TFootballer; TFootballer = object(TPeople) code_position: TPosition; code_team: integer; coeff: byte; constructor init(AName: string; AnAge: integer; team, position: string; ACoeff: byte); procedure print_info; end; TTeam = object code_team: integer; squad: array[1 .. 15] of PTFootballer; constructor init(team: string); private players: integer; procedure test_print; end; const s_position: array[TPosition] of string = ( 'goalkeeper', 'defender', 'midfielder', 'forward' ); max_teams = 5; s_team: array[1 .. max_teams] of string = ( 'chelsea', 'real', 'spartak', 'dinamo', 'pahtakor' { :) } ); constructor TPeople.init(AName: string; AnAge: integer); begin age := AnAge; name := AName; end; constructor TFootballer.init(AName: string; AnAge: integer; team, position: string; ACoeff: byte); var p: TPosition; i: integer; begin inherited init(AName, AnAge); for p := low(Tposition) to high(TPosition) do if s_position[p] = position then begin code_position := p; break; end; for i := 1 to max_teams do if s_team[i] = team then begin code_team := i; break; end; coeff := ACoeff; end; procedure TFootballer.print_info; begin writeln( ' name: ', name:12, ' age: ', age:3, ' team: ', s_team[code_team]:10, ' pos:', s_position[code_position]:10, ' coeff:', coeff:4 ) end; const max_footballers = 50; var count_footballers: integer; footb_array: array[1 .. max_footballers] of PTFootballer; procedure init_footballers(const filename: string); function _toint(s: string): integer; var _result, _error: integer; begin val(s, _result, _error); _toint := _result; end; function _copy(var s: string; count: integer): string; begin _copy := copy(s, 1, pred(count)); delete(s, 1, count); end; var f: text; s: string; f_n, f_t, f_p: string; f_a, f_c: integer; begin assign(f, filename); reset(f); count_footballers := 0; while not seekeof(f) do begin inc(count_footballers); readln(f, s); f_n := _copy(s, pos(' ', s)); f_a := _toint(_copy(s, pos(' ', s))); f_t := _copy(s, pos(' ', s)); f_p := _copy(s, pos(' ', s)); f_c := _toint(s); new( footb_array[count_footballers], init(f_n, f_a, f_t, f_p, f_c) ); end; close(f); end; constructor TTeam.init(team: string); var i: integer; begin for i := 1 to max_teams do if s_team[i] = team then begin code_team := i; break; end; players := 0; for i := 1 to count_footballers do begin if footb_array[i]^.code_team = code_team then begin inc(players); squad[players] := footb_array[i]; end; end; end; procedure TTeam.test_print; var i: integer; begin writeln('squad list:'); for i := 1 to players do squad[i]^.print_info; end; var team: TTeam; i: integer; begin init_footballers('football.txt'); for i := 1 to count_footballers do footb_array[i]^.print_info; team.init('spartak'); team.test_print; end.