uses crt const count subjects 100 type rec record surname string 30 ma

 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
uses crt;
const n=3; {count subjects}
m=100;
type rec = record
surname:string[30];
mark:record
subject:array[1..n] of byte;
end;
end;
mas = array[1..m] of rec;
var student,expelStudent:mas;
k,kExpel:integer;
{----------------------------------------------------------------}
procedure fillTheList(var r:mas; var k:integer);
var i,j:integer;
begin
write('Count records: ');
readln(k);
for i:=1 to k do
begin
write('Surname: ');
readln(r[i].surname);
for j:=1 to n do
r[i].mark.subject[j]:=random(4)+2;
end;
end;
{----------------------------------------------------------------}
procedure printList(r:mas; k:integer);
var i,j:integer;
begin
writeln('+--------------------------------------------------------+');
writeln('| Surname | Higer math | Programming | Physics |');
writeln('|--------------------------------------------------------|');
for i:=1 to k do
begin
write('| ',r[i].surname:12,' | ');
for j:=1 to n do
write(r[i].mark.subject[j]:11,' | ');
writeln;
end;
writeln('+--------------------------------------------------------+');
end;
{----------------------------------------------------------------}
procedure whoExpel(r:mas; var count:integer; var expelList:mas);
var i,j:integer;
begin
count:=1;
for i:=1 to k do
for j:=1 to n do
if r[i].mark.subject[j] = 2 then
begin
expelList[count]:=r[i];
count:=count+1;
break;
end;
count:=count-1;
end;
{----------------------------------------------------------------}
procedure sortRecords(var r:mas; k:integer);
2var i,j:integer;
dummyRec:rec;
begin
for i:=1 to k-1 do
for j:=i+1 to k do
if r[i].surname > r[i+1].surname then
begin
dummyRec:=r[i];
r[i]:=r[i+1];
r[i+1]:=dummyRec;
end;
end;
{----------------------------------------------------------------}
begin
clrscr;
randomize;
fillTheList(student,k);
printList(student,k);
whoExpel(student,kExpel,expelStudent);
sortRecords(expelStudent,kExpel);
writeln('Expel List');
printList(expelStudent,kExpel);
writeln('Press "Y" for exit');
while readkey <> 'y' do
readkey;
end.