unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Memo1: TMemo;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    OpenDialog1: TOpenDialog;
    SaveDialog1: TSaveDialog;
    SaveDialog2: TSaveDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
  end;

    Type
    TStudent = record
    FIO: string[40];
    otc: array[1..3] of word;
    sball: extended;
    end;

    var
    Form1: TForm1;
    Fz  : file of  Tstudent;
    Ft  : TextFile;
    Stud : array[1..100] of Tstudent;
    nzap : integer;
    FileNameZ, FileNameT : string;

implementation

{$R *.dfm}

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


procedure TForm1.Button1Click(Sender: TObject);
begin
nzap:=nzap+1;
with stud[nzap] do begin
           FIO:=Edit1.Text;
           otc[1]:=StrToInt(Edit2.Text);
           otc[2]:=StrToInt(Edit3.Text);
           otc[3]:=StrToInt(Edit4.Text);
           sball:=(otc[1]+otc[2]+otc[3])/3;
           end;

with stud[nzap] do
Memo1.Lines.Add(fio+' '+IntToStr(otc[1])+' '+ IntToStr(otc[2])+' '+IntToStr(otc[3]));
Edit1.Clear;
Edit2.Clear;
Edit3.Clear;
Edit4.Clear;
end;

procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
OpenDialog1.Title :='Создание БД';								//???? ???????
 if OpenDialog1.Execute then
   begin
    FileNameZ:= OpenDialog1.FileName;
    AssignFile(Fz, FileNameZ);
    Rewrite(Fz);

    for i:=1 to nzap do
        begin
        write(Fz, stud[i]);
        end;
    CloseFile(fz);
   end;
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 begin
     Memo1.Lines.Add(fio+''+IntToStr(otc[1])+''+IntToStr(otc[2])+''+IntToStr(otc[3]));
                         end;
     end;
CloseFile(fz);
end;

procedure TForm1.Button5Click(Sender: TObject);
var i:integer;
begin
if SaveDialog1.Execute then
    begin
    FileNameT:= SaveDialog1.FileName;
    AssignFile(Ft, FileNameT);
    Rewrite(Ft);
    Writeln(ft,Memo1.Text); 										// ????????? ????
    CloseFile(Ft);
    end;
end;

procedure TForm1.Button4Click(Sender: TObject);
var sballU, x: extended;
    i: integer;
    st : TStudent;
begin
 memo1.clear;
 x:=0;
 for i:=1 to nzap do
        begin
        x:=x+stud[i].sball;
        end;
 sballU:=x/nzap;

 memo1.lines.add('средний балл по университету'+floattostrf(sballU,fffixed,8,2));

 {for i:=1 to nzap-1 do
                begin
                if stud[i].sball<stud[i+1].sball then
                        begin
                        st:=stud[i];
                        stud[i]:=stud[i+1];
                        stud[i+1]:=st;
                        end;
                end;}

 for i:=1 to nzap do
 if stud[i].sball>=sballU then
 with stud[i] do
 Memo1.Lines.Add(fio+' '+FloatToStrf(sball,fffixed,4,2));
end;

end.
