unit m9;

interface

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

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit4: TEdit;
Edit5: TEdit;
Label7: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Label8: TLabel;
Label9: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation
type TStudent=record
Fio:string[50];
Adress:string[50];
Marks:array[1..4]of extended;
end;
var
n1,n2:integer;
s:string[50];
a,b:array[1..100]of TStudent;
f:TextFile;
{$R *.DFM}




procedure TForm1.FormCreate(Sender: TObject);
begin
n1:=0;
n2:=0;
StringGrid1.Cells[0,0]:='ФИО';
StringGrid1.Cells[1,0]:='Адрес';
StringGrid1.Cells[2,0]:='Математика';
StringGrid1.Cells[3,0]:='Физика';
StringGrid1.Cells[4,0]:='Язык';
StringGrid1.Cells[5,0]:='Среднее';
StringGrid2.Cells[0,0]:='ФИО';
StringGrid2.Cells[1,0]:='Адрес';
StringGrid2.Cells[2,0]:='Математика';
StringGrid2.Cells[3,0]:='Физика';
StringGrid2.Cells[4,0]:='Язык';
StringGrid2.Cells[5,0]:='Среднее';
end;

procedure sort(var m:array of TStudent;n:integer);
var r:TStudent;
s1,s2:string[50];
i,j:integer;
begin
with r do
begin
Fio:='';
Adress:='';
Marks[1]:=0;
Marks[2]:=0;
Marks[3]:=0;
Marks[4]:=0;
end;
{ for i:=1 to n do
for j:=1 to n do
begin
with m[i]do
s1:=Fio;
with m[j]do
s2:=Fio;
if s2>s1
then begin
r:=m[i];
m[i]:=m[j];
m[j]:=r;
end;
end; }
for i:=0 to 5 do
for j:=1 to n1-1 do
Form1.Stringgrid1.Cells[i,j]:='';
For i:=1 to n1 do
with a[i] do
begin
Form1.StringGrid1.Cells[0,i]:=Fio;
Form1.StringGrid1.Cells[1,i]:=Adress;
Form1.StringGrid1.Cells[2,i]:=FloatToStr(Marks[1]);
Form1.StringGrid1.Cells[3,i]:=FloatToStr(Marks[2]);
Form1.StringGrid1.Cells[4,i]:=FloatToStr(Marks[3]);
Form1.StringGrid1.Cells[5,i]:=FloatToStr(Marks[4]);
end;
for i:=0 to 5 do
for j:=1 to n2-1 do
Form1.Stringgrid2.Cells[i,j]:='';
For i:=1 to n2 do
with b[i] do
begin
Form1.StringGrid2.Cells[0,i]:=Fio;
Form1.StringGrid2.Cells[1,i]:=Adress;
Form1.StringGrid2.Cells[2,i]:=FloatToStr(Marks[1]);
Form1.StringGrid2.Cells[3,i]:=FloatToStr(Marks[2]);
Form1.StringGrid2.Cells[4,i]:=FloatToStr(Marks[3]);
Form1.StringGrid2.Cells[5,i]:=FloatToStr(Marks[4]);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
m:extended;
begin
try
n1:=n1+1;
with a[n1] do
begin
Fio:=Edit1.Text;
Adress:=Edit2.Text;
Marks[1]:=StrToFloat(Edit3.Text);
Marks[2]:=StrToFloat(Edit4.Text);
Marks[3]:=StrToFloat(Edit5.Text);
Marks[4]:=(Marks[1]+Marks[2]+Marks[3])/3;
Sort(a,n1);
m:=Marks[4];
end;
if m>4.5
then
begin
n2:=n2+1;
with b[n2] do
begin
Fio:=Edit1.Text;
Adress:=Edit2.Text;
Marks[1]:=StrToFloat(Edit3.Text);
Marks[2]:=StrToFloat(Edit4.Text);
Marks[3]:=StrToFloat(Edit5.Text);
Marks[4]:=(Marks[1]+Marks[2]+Marks[3])/3;
Sort(a,n1);
end;
end;
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';

except
ShowMessage('Необходимо заполнить все поля');
end;
end;


procedure rec;
var i:integer;
begin
for i:=1 to n1 do
with a[i] do
begin
Write(f,Fio+';'+Adress+';'+FloatToStr(Marks[1])+';'
+FloatToStr(Marks[2])+';'+FloatToStr(Marks[3])+';'+FloatToStr(Marks[4]));
if i<>n1
then writeln(f);
end;
CloseFile(f);
end;

procedure outfile;
var
st1,st2:string[50];
k:integer;
c1,c2,c3,c4,m:extended;
ch:char;
usl:boolean;
begin
while not seekeof(f)do
begin
n1:=n1+1;
k:=0;
st1:='';
st2:='';
usl:=true;
while usl=true do
begin
read(f,ch);
if ch<>';' then
case k of
0:st1:=st1+ch;
1:st2:=st2+ch;
2:c1:=StrToFloat(ch);
3:c2:=StrToFloat(ch);
4:c3:=StrToFloat(ch);
5:begin
readln(f);
usl:=false;
end;
end;
if ch=';'
then inc(k);
end;
with a[n1] do
begin
Fio:=st1;
Adress:=st2;
Marks[1]:=c1;
Marks[2]:=c2;
Marks[3]:=c3;
Marks[4]:=(Marks[1]+Marks[2]+Marks[3])/3;
Sort(a,n1);
m:=Marks[4];
end;
end;
if m>4.5
then
begin
n2:=n2+1;
with b[n2] do
begin
Fio:=st1;
Adress:=st2;
Marks[1]:=c1;
Marks[2]:=c2;
Marks[3]:=c3;
Marks[4]:=(Marks[1]+Marks[2]+Marks[3])/3;
Sort(b,n2);
end;
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
SaveDialog1.Title:='Создать новый файл';
if SaveDialog1.Execute
then begin
s:=SaveDialog1.FileName;
AssignFile(f,s);
ReWrite(f);
rec;
end;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
OpenDialog1.Title:='Открыть файл';
if OpenDialog1.Execute
then begin
s:=OpenDialog1.FileName;
AssignFile(f,s);
Reset(f);
outfile;
end;
end;

end.
Соседние файлы в папке Ведомость абитуриентов2 в Минске
  • #
    15.06.201411.07 Кб64m9.dcu
  • #
    15.06.20141.89 Кб64m9.dfm
  • #
    15.06.20145.74 Кб64m9.pas
  • #
    15.06.2014922 б64p9.dof
  • #
    15.06.2014176 б64p9.dpr
  • #
    15.06.2014876 б64p9.res