unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    BitBtn1: TBitBtn;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure BitBtn1Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
    Tstudent = record
     FIO: string[40];
     Attrib: array[1..2] of integer;
     Mark: extended;
    end;
var
 Fz: file of Tstudent;
 Stud: array[1..100] of Tstudent;
 nzap: integer;
 FileNameZ: string;
var
 Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
 Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit4.Clear;
 Memo1.Clear;
 Button1.Hide;
 nzap:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
 nzap:=nzap+1;
 with stud[nzap] do begin
  FIO:=Edit1.Text;
  Attrib[1]:=StrToInt(Edit2.Text);
  Attrib[2]:=StrToInt(Edit4.Text);
  Mark:=StrToFloat(Edit3.Text);
  Memo1.Lines.Add(FIO +' '+IntToStr(Attrib[1])+' '+FloatToStr(Mark)+
' '+IntToStr(Attrib[2]));
  Write(fz,Stud[nzap]);
  end;
  Edit1.Clear; Edit2.Clear; Edit3.Clear; Edit4.Clear;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 OpenDialog1.Title:='Создать новый файл';
 if OpenDialog1.Execute then
  begin
   FileNameZ:=OpenDialog1.FileName;
   AssignFile(Fz,FileNameZ);
   Rewrite(Fz);
  end;
 Button1.Show;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
FileNameZ:= OpenDialog1.FileName;
AssignFile(Fz, FileNameZ);
Reset(Fz);
end;
nzap:=0;
while not eof(fz) do begin
nzap:=nzap+1;
Read(fz,stud[nzap]);
with stud[nzap] do
Memo1.Lines.Add(FIO +' '+IntToStr(Attrib[1])+' '+FloatToStr(Mark)+
' '+IntToStr(Attrib[2]));
end;
Button1.Show;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
 CloseFile(fz);
end;

procedure TForm1.Button4Click(Sender: TObject);
 var stud3,stud2: array[1..100] of Tstudent;
     nzap3,nzap2,j,i,k,num: integer;
     a: array[1..100] of array[1..2] of extended;
     max,prom:array[1..2] of extended;
     b: array[1..100] of integer;

begin
 for k:=1 to nzap do begin
    a[k][1]:=stud[k].Mark;
    a[k][2]:=k;
   end;
   for k:=1 to nzap do begin
    max[1]:=-1;
    for j:=1 to nzap do
     if a[j][1]>max[1] then begin
                             prom[1]:=max[1];
                             prom[2]:=max[2];
                             max[1]:=a[j][1];
                             max[2]:=a[j][2];
                             a[j][1]:=prom[1];
                             a[j][2]:=prom[2];
                            end;
    b[nzap+1-k]:=trunc(max[2]);
   end;
   for k:=1 to nzap do begin
    num:=b[k];
    stud3[k]:=stud[num];
   end;
   for k:=1 to nzap do
    stud[nzap+1-k]:=stud3[k];

 nzap2:=0;
 nzap3:=0;
 for i:=1 to nzap do
  if stud[i].Attrib[2]<70000 then begin
                                   nzap2:=nzap2+1;
                                   stud2[nzap2]:=stud[i];
                                  end
    else begin
          nzap3:=nzap3+1;
          stud3[nzap3]:=stud[i];
         end;   

 for i:=1 to nzap2 do
  stud[i]:=stud2[i];
 for i:=1 to nzap3 do
  stud[i+nzap2]:=stud3[i];
  Rewrite(fz);
  Memo1.Clear;
  for i:=1 to nzap do
  Write(fz,Stud[i]);
end;

end.
