Rutinas de modificar y eliminar registros en un archivo
Publicado por Roberto (19 intervenciones) el 15/01/2016 10:44:56
Hola, alguien sabe alguna rutina para modificar y otra rutina para eliminar en un archivo? Este es mi código, le faltan esas dos rutinas
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
{Elaborado por El Varon}
program turismotoursven;
uses
crt;
const
archivo = 'mitrabajo.dat';
type
elturista = record
Numeropas : longint;
Nombreape : string[60];
origenpas:char;
end;
var
f : file of elturista;
turis : elturista;
function existearchivo : boolean;
begin
assign(f,archivo);
{$I-} reset(f); {$I+}
if ioresult <> 0 then
existearchivo := false
else
begin
existearchivo := true;
end;
end;
procedure entradadatos;
var
tec : char;
begin
clrscr;
writeln(' ****** Entrada Datos turista ******');
writeln;
write(' Entre Nombre y apellido : ');
readln(turis.Nombreape);
write(' Entre Numero pasaporte : ');
readln(turis.Numeropas);
write('Origen del pasaporte [V]Venezolano, [E]extranjero: ');
readln(turis.origenpas);
writeln;
writeln(' Se Guardar Los Datos ');
writeln;
writeln(' Datos Correctos [S/N]');
repeat
tec := upcase(readkey);
until tec in['S','N'];
if tec = 'S' then
begin
if existearchivo = true then
begin
seek(f,filesize(f));
write(f,turis);
close(f);
end
else
begin
rewrite(f);
seek(f,0);
write(f,turis);
close(f);
end;
end;
end;
procedure busqueda_turista;
var
ddn : longint;
tt, vus : longint;
encon : boolean;
begin
if existearchivo = true then
begin
writeln(' Buscar Un turista ');
writeln;
write(' Entre Numero de pasaporte : ');
readln(ddn);
encon := false;
for vus := 0 to filesize(f) - 1 do
begin
seek(f,vus);
read(f,turis);
if turis.numeropas = ddn then
begin
encon := true;
break;
end;
end;
if encon = true then
begin
writeln('Nombre y apellido: ',turis.Nombreape);
writeln('Numero de pasaporte: ',turis.numeropas);
writeln('Origen de pasaporte :',turis.origenpas);
end
else
writeln(' No se encuentran datos del turista ');
close(f);
writeln;
writeln(' Pulse Una Tecla');
readkey;
end
else
begin
writeln(' Error De Archivo O No Existe Pulse Una Tecla');
readkey;
end;
end;
procedure ordenar; {*Funcion que ordena los datos dentro del registro*}
var
turis, E1, A : elturista; {registros auxiliares ncompletos de turistas}
ar, ar2 : longint; {contadores de iteraciones}
begin
assign (f, archivo);
{$I-}reset(f);{$I+}
if ioresult<>0 then
begin
writeln(' Error');
readln;
exit;
end
else
begin
for ar := 0 to filesize(f) - 1 do
begin
seek(f,ar);
read(f,turis);
begin
for ar2 := ar + 1 to filesize(f) - 1 do
begin
seek(f,ar2);
read(f,E1);
if turis.Numeropas > E1.Numeropas then
begin
A := turis;
turis := E1;
E1 := A;
seek(f,ar);
write(f,turis);
seek(f,ar2);
write(f,E1);
end;
{end if}
end;
{end for}
end;
end;
{end for}
end;
{end if}
close(f);
end;
procedure mostrar; {*Funcion que muestra la lista de los turistas*}
var
z : longint; {Contador de iteraciones}
begin
assign(f,archivo);
{$I-} reset(f); {$I+}
if ioresult <> 0 then
begin
writeln;
writeln(' Error');
readkey;
exit;
end
else
begin
writeln;
writeln(' >>> Registro de Turistas <<<');
writeln;
for z := 0 to filesize(f) - 1 do
begin
seek(f,z);
read(f,turis);
writeln(' ',turis.Numeropas,' ',turis.Nombreape);
end;
{end for}
close(f);
writeln;
writeln(' <<< Pulse Una Tecla Para Regresar >>>');
readkey;
end;
{end if}
end;
procedure contador; {*Funcion que muestra la lista de los turistas*}
var
t : longint; {Contador de iteraciones}
turis: elturista;
vene,extra:integer;
begin
assign(f,archivo);
{$I-} reset(f); {$I+}
if ioresult <> 0 then
begin
writeln;
writeln(' Error');
readkey;
exit;
end
else
begin
vene := 0;
extra := 0;
for t := 0 to filesize(f) - 1 do
begin
seek(f,t);
read(f,turis);
if (turis.origenpas='V') then
begin
vene := vene + 1;
end
else
begin
extra := extra + 1;
end;
clrscr;
writeln('<<< Datos>>>');
writeln;
WriteLn('Cantidad de venezolanos ',vene);
WriteLn('Cantidad de extranjeros ',extra);
end;
{end for}
close(f);
writeln;
writeln(' <<< Pulse Una Tecla Para Regresar >>>');
readkey;
end;
{end if}
end;
procedure menu;
var
sal : boolean;
tecla : char;
begin
sal := false;
repeat
clrscr;
writeln(' ***** Menu General *****');
writeln;
writeln(' 1 = Entrada turista');
writeln(' 2 = Mostrar Un turista');
writeln(' 3 = Modicar datos');
writeln(' 4 = Eliminar Un turista');
writeln(' 5 = Listado ordenado');
writeln(' 6 = Informacion: Contadores');
writeln(' 7 = Salir');
writeln;
writeln(' >>> Elija Opcion <<<');
repeat
tecla := readkey;
until tecla in['1','2','3','4','5','6','7'];
clrscr;
case tecla of
'1' : entradadatos;
'2' : busqueda_turista;
'3' : ;
'4' : ;
'5' :
begin
ordenar;
mostrar;
end;
'6' : contador;
'7' : sal := true;
end;
until sal = true;
end;
begin
menu;
end.
Valora esta pregunta


0