-
Notifications
You must be signed in to change notification settings - Fork 0
/
ARXTIPUS.PAS
executable file
·202 lines (170 loc) · 3.51 KB
/
ARXTIPUS.PAS
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
PROGRAM ArxiusDeTipus;
USES Crt;
TYPE
Alumne=record
Nom: String [20];
Edat: Word;
nota:real;
End;
VAR
f:FILE of Alumne;
tmp: FILE of ALumne;
AUX: Alumne;
option: word;
ch:char;
BorraNom:string;
Procedure Afegir;
begin
write('Nom: ');
readln(Aux.nom);
write('Edat: ');
readln(Aux.edat);
write('Nota: ');
readln(aux.nota);
reset(f);
seek(f,filesize(f));
write(f,Aux);
close(f);
end;
Procedure Visualitzar;
begin
clrscr;
reset(f);
while not eof (f) do begin
clrscr;
read(f,aux);
If Aux.edat <> 0 then begin
writeln(aux.Nom);
writeln(aux.Edat);
writeln(aux.Nota:2:2);
ch:=readkey;
End;
End;
close(f);
End;
Procedure Borrar;
begin
write('Nom a borrar?: ');
readln(BorraNom);
clrscr;
reset(f);
while not eof (f) do begin
read(f,aux);
If (aux.nom=BorraNom) then begin
seek(f,filepos(f)-1);
aux.edat:=0;
write(f,aux);
End;
End;
close(f);
End;
Procedure Modificar;
Begin
write('Nom a modificar?: ');
readln(BorraNom);
clrscr;
reset(f);
while not eof (f) do begin
read(f,aux);
If (aux.nom=BorraNom) then begin
seek(f,filepos(f)-1);
write('Nom: ');
readln(aux.nom);
write('Edat: ');
readln(aux.edat);
write('Nota: ');
readln(aux.nota);
write(f,aux);
End;
End;
close(f);
End;
Procedure Mitja;
var m:real;
c:word;
Begin
c:=0;
m:=0;
reset(f);
while not eof (f) do begin
read(f,aux);
if (aux.edat <> 0) then begin
c:=c+1;
m:=(m+aux.nota)/c;
End;
End;
write('La mitja de notes ‚s ',m:2:2);
readln;
End;
Procedure Sortir; {Copia el fitxer amb un altre de temporal i el torna
a copiar sense camp edat=0}
VAR
f_aux:File of alumne;
BEGIN
Assign(f_aux,'DADES.TMP');
{$I-}
reset(f_aux);
close(f_aux);
{$I+}
If IOResult <> 0 then begin
rewrite(f_aux);
close(f_aux);
End;
reset(f);
reset(f_aux);
seek(f_aux,0);
seek(f,0);
While not eof (f) do begin
read(f,aux);
if (aux.edat > 0) then begin
write(f_aux,aux);
End;
End;
close(f);
close(f_aux);
reset(f_aux);
seek(f_aux,0);
rewrite(f);
seek(f,0);
While not eof (f_aux) do begin
read(f_aux,aux);
write(f,aux);
End;
close(f);
close(f_aux);
erase(f_aux);
END;
{ M A I N }
BEGIN
Assign(f,'Dades.dat');
{$I-}
reset(f);
close(f);
{$I+}
If IOResult <> 0 then begin
rewrite(f);
close(f);
End;
repeat
clrscr;
textcolor(white);
writeln('1. Visualitzar');
writeln('2. Afegir');
writeln('3. Borrar');
writeln('4. Modificar');
writeln('5. Mitja');
writeln;
writeln('0. SORTIR i COMPACTAR');
writeln;
write('Opci¢: ');
readln(option);
case (option) of
1:visualitzar;
2:Afegir;
3:Borrar;
4:Modificar;
5:Mitja;
0:sortir;
End; {del case}
Until (Option=0);
END.