uses crt const count subjects 100 databaseFile database txt expelFile

  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
172
173
174
175
176
177
178
179
180
181
182
183
uses crt;
const n=3; {count subjects}
m=100;
databaseFile='database.txt';
expelFile='expel.txt';
type rec = record
surname:string[30];
mark:record
higherMath:integer;
programming:integer;
physics:integer;
end;
end;
mas = array[1..m] of rec;
var f1:file of rec;
pressedKey:char;
nameFile:string;
{----------------------------------------------------------------}
procedure fillTheList(nameFile:string);
var i,k:integer;
r:rec;
begin
clrscr;
assign(f1,nameFile);
rewrite(f1);
write('Count records: ');
readln(k);
for i:=1 to k do
begin
write('Surname: ');
readln(r.surname);
r.mark.higherMath:=random(4)+2;
r.mark.programming:=random(4)+2;
r.mark.physics:=random(4)+2;
write(f1,r);
end;
close(f1);
end;
{----------------------------------------------------------------}
procedure addRecord(nameFile:string);
var i:integer;
r:rec;
begin
clrscr;
assign(f1,nameFile);
reset(f1);
write('Surname: ');
readln(r.surname);
r.mark.higherMath:=random(4)+2;
r.mark.programming:=random(4)+2;
r.mark.physics:=random(4)+2;
seek(f1,filesize(f1));
write(f1,r);
close(f1);
end;
{----------------------------------------------------------------}
procedure editRecord(nameFile:string);
var i:integer;
r:rec;
surname:string;
flag:boolean;
begin
clrscr;
assign(f1,nameFile);
reset(f1);
writeln('Which surname of student we need to edit? Surname: ');
readln(surname);
i:=0;
flag:=true;
while eof(f1) or flag do
begin
seek(f1,i);
read(f1,r);
if (r.surname = surname) then
begin
writeln('New surname');
readln(r.surname);
write('Higher math: ');
readln(r.mark.higherMath);
write('Programming: ');
readln(r.mark.programming);
write('Physics: ');
readln(r.mark.physics);
flag:=false;
seek(f1,i);
write(f1,r);
end;
inc(i);
end;
close(f1);
end;
{----------------------------------------------------------------}
procedure printList(nameFile:string);
var i:integer;
r:rec;
begin
clrscr;
assign(f1,nameFile);
reset(f1);
i:=0;
writeln('+------------+------------+-------------+---------+');
writeln('| Surname | Higher math| Programming | Physics |');
writeln('+------------+------------+-------------+---------+');
while not eof(f1) do
begin
seek(f1,i);
read(f1,r);
write('| ',r.surname:10,' | ');
write(r.mark.higherMath:10,' | ');
write(r.mark.programming:11,' | ');
write(r.mark.physics:7,' | ');
writeln;
inc(i);
end;
close(f1);
writeln('+-------------------------------------------------+');
end;
{----------------------------------------------------------------}
procedure whoExpel(nameFileBase:string; nameFileExpel:string);
var i:integer;
r:rec;
f2:file of rec;
begin
assign(f1,nameFileBase);
assign(f2,nameFileExpel);
reset(f1);
rewrite(f2);
i:=0;
while not eof(f1) do
begin
seek(f1,i);
read(f1,r);
if (r.mark.higherMath = 2) or
(r.mark.programming = 2) or
(r.mark.physics = 2) then
write(f2,r);
inc(i);
end;
end;
{----------------------------------------------------------------}
procedure getCommands;
begin
window(55,1,80,25);
writeln('Commands: ');
writeln('1 - exit');
writeln('2 - edit record');
writeln('3 - add record');
writeln('4 - cleen screen');
writeln('5 - fill the list');
writeln('6 - print expel list');
writeln('7 - print all list');
writeln('8 - form expel list');
end;
{----------------------------------------------------------------}
begin
randomize;
printList('list.txt');
clrscr;
gotoXY(20,1);
repeat
getCommands;
window(1,1,80,25);
write('Command: ');
clreol;
readln(pressedKey);
window(1,2,54,25);
case pressedKey of
'2': editRecord(databaseFile);
'3': addRecord(databaseFile);
'4': clrscr;
'5': fillTheList(databaseFile);
'6': printList(expelFile);
'7': printList(databaseFile);
'8': whoExpel(databaseFile,expelFile);
end;
until pressedKey = '1';
end.