1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
| unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
BitBtn1: TBitBtn;
Edit5: TEdit;
Label6: TLabel;
Button5: TButton;
procedure FormCreate(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
Type
TStudent = record
FIO,Adres: string[40]; // Поле ф.и.о,адрес.
otc: array[1..3] of word; // Поле массива оценок
sball : extended; // Поле среднего балла
end;
Var
Fz : file of Tstudent; // Файл типа запись
Ft : TextFile; // Текстовой файл
Stud : array[1..100] of Tstudent; // Массив записей
nzap : integer; // Номер записи
FileNameZ, FileNameT : string; // Имя файла
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
CloseFile(fz); // Закрытие файла записей при нажатии на кнопку “Сlose”
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenDialog1.Execute then // Выполнение стандартного диалога выбора имени файла
begin
FileNameZ:= OpenDialog1.FileName; // Возвращение имени дискового файла
AssignFile(Fz, FileNameZ); // Связывание файловой переменной Fz c именем файла
Reset(Fz); // Открытие существующего файла
end;
while not eof(fz) do begin
nzap:=nzap+1;
Read(fz,stud[nzap]); // Чтение записи из файла
with stud[nzap] do
Memo1.Lines.Add(fio+' '+Adres+' '+IntToStr(otc[1])+' '+IntToStr(otc[2])+' '+IntToStr(otc[3]));
end;
Button1.Show; // Сделать видимой кнопку "Ввести запись"
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
OpenDialog1.Title :='Создать новый файл'; // Изменение заголовка окна диалога
if OpenDialog1.Execute then // Выполнение стандартного диалога выбора имени файла
begin
FileNameZ:= OpenDialog1.FileName; // Возвращение имени дискового файла
AssignFile(Fz, FileNameZ); // Связывание файловой переменной Fz c именем файла
Rewrite(Fz); // Создание нового файла
end;
Button1.Show;
end;
procedure TForm1.Button3Click(Sender: TObject);
var i,j : word;
st : TStudent;
begin
for i:=1 to nzap-1 do // Сортировка массива записей
for j:=i+1 to nzap do
if Stud[i].sball < Stud[j].sball then begin
st:=Stud[i];
Stud[i]:=Stud[j];
Stud[j]:=st;
end;
Memo1.Clear;
for i:=1 to nzap do // Вывод в окно Memo1 отсортированных записей
with stud[i] do
Memo1.Lines.Add(IntToStr(i)+' '+fio+' '+FloatToStrf(sball,fffixed,4,2));
end;
procedure TForm1.Button4Click(Sender: TObject);
var i:word;
begin
if SaveDialog1.Execute then // Выполнение стандартного диалога выбора имени файла
begin
FileNameT:= SaveDialog1.FileName; // Возвращение имени дискового файла
AssignFile(Ft, FileNameT); // Связывание файловой переменной Ft c именем файла
Rewrite(Ft); // Открытие нового текстового файла
end;
for i:=1 to nzap do
with stud[i] do Writeln(Ft,i:4,'. ',fio,sball:8:2); // Запись в текстовой файл
CloseFile(Ft); // Закрытие текстового файла
end;
procedure TForm1.Button5Click(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;
Memo1.Lines.Add(fio+''+Adres+' '+IntToStr(otc[1])+' '+ IntToStr(otc[2])+' '+IntToStr(otc[3]));
end;
Write(fz,Stud[nzap]); // Запись в файл
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit4.Text:='';
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
CloseFile(fz); // Закрытие файла записей при нажатии на кнопку
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Edit3.Text:='';
Edit4.Text:='';
Edit5.Text:='';
Memo1.Clear;
Button1.Hide; // Сделать невидимой кнопку "Ввести запись"
nzap:=0;
end;
end. |