Pascal/Turbo Pascal - Rutinas de modificar y eliminar registros en un archivo

 
Vista:
sin imagen de perfil
Val: 31
Ha disminuido 1 puesto en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

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
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Rutinas de modificar y eliminar registros en un archivo

Publicado por ramon (2158 intervenciones) el 23/01/2016 11:57:31
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
{Mira es tu programa con lo que pides}
 
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 eliminar(nn : longint);
    var
      tempo : file of elturista;
      gf : elturista;
      long1, long2 : longint;
     begin
      assign(f,archivo);
   {$I-} reset(f); {$I+}
   if ioresult <> 0 then
   begin
      writeln;
      writeln(' Error');
      readkey;
      exit;
   end
 else
     begin
       long2 := 0;
       assign(tempo,'temporal.tem');
       rewrite(tempo);
       for long1 := 0 to filesize(f) - 1 do
       begin
          seek(f,long1);
          read(f,turis);
          if turis.Numeropas <> nn then
          begin
            seek(tempo,long2);
            write(tempo,turis);
            long2 := long2 + 1;
          end;
       end;
       close(f);
       close(tempo);
       erase(f);
       rename(tempo,archivo);
     end;
   end;
 
   procedure modificar(mm : longint);
   var
      long1, long2 : longint;
      enco : boolean;
      plt : char;
     begin
      assign(f,archivo);
   {$I-} reset(f); {$I+}
   if ioresult <> 0 then
   begin
     writeln;
     writeln(' Error');
     readkey;
     exit;
   end
 else
     begin
       long2 := 0;
       enco := false;
       for long1 := 0 to filesize(f) - 1 do
       begin
          seek(f,long1);
          read(f,turis);
          if turis.Numeropas = mm then
          begin
             enco := true;
             long2 := long1;
             break;
          end;
       end;
         if enco = true then
         begin
           clrscr;
           writeln('   Los Datos Son = [1] = ',turis.Numeropas,'  [2] = ',
           turis.Nombreape,'   [3] = ',turis.origenpas,'   [4] = Termina');
           writeln;
           writeln('   Elija Numero A Modificar');
         repeat
          repeat
           plt := readkey;
          until plt in['1','2','3','4'];
      case plt of
   '1' : begin
           write('  Numero Pasaporte : ');
           readln(turis.Numeropas);
         end;
   '2' : begin
           write('  Nombre Apellido  : ');
           readln(turis.Nombreape);
         end;
   '3' : begin
           write('  Origen del pasaporte [V]Venezolano, [E]extranjero : ');
           readln(turis.origenpas);
         end;
        end;
         if plt <> '4' then
         begin
         clrscr;
         writeln('   Los Datos Son = [1] = ',turis.Numeropas,'  [2] = ',
         turis.Nombreape,'   [3] = ',turis.origenpas,'   [4] = Termina');
         writeln;
         writeln('   Elija Numero A Modificar');
         end;
         until plt = '4';
         seek(f,long2);
         write(f,turis);
         close(f);
         end
      else
         begin
            writeln('   Numero No Encontrado Pulse Una Tecla ');
            readkey;
         end;
     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;
     nuw : longint;
     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' : begin
        writeln('   Modificacion Entre Numero Pasaporte');
        write('  Numero : ');
        readln(nuw);
        modificar(nuw);
        end;
  '4' : begin
        writeln('   Eliminacion Entre Numero Pasaporte');
        write('  Numero : ');
        readln(nuw);
        eliminar(nuw);
        end;
  '5' : begin
        ordenar;
        mostrar;
        end;
  '6' : contador;
  '7' : sal := true;
     end;
     until sal = true;
   end;
 
 
 
 
   begin
      menu;
   end.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
3
Comentar
sin imagen de perfil

Rutinas de modificar y eliminar registros en un archivo

Publicado por crisbelt guerra (4 intervenciones) el 23/02/2016 15:52:37
hola amigo ramon me gustaria si x favor me ayudas con el mismo programa pero añadiendole fecha de expedicion del pasaporte, fecha dertificado de vacuna y fecha de declaracion de impuesto, tomando en cuenta que si el pasaporte es expedido en venezuela caducara en un año en caso contrario caduca en dos años y el certificado de vacuna y declaracion de impuesto son valido por un año.. en el contador donde muestro el numero de pasaporte venezolano y extranjero tambien tengo que mostrar cuantos turistas tienen certificado vencido y declaracion vencida y cuantos tusristas tienen recaudos vigentes.. x favor se te agradece la ayuda es para ya me lo puedes enviar al correo o x aca.. [email protected] mil gracias de antemano.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de salazarvalbuena

Rutinas de modificar y eliminar registros en un archivo

Publicado por salazarvalbuena (15 intervenciones) el 24/02/2016 09:10:14
Aquí está el programa completo, lo comparto, lo presenté ayer y el profesor quedó impresionado.

http://hastebin.com/nadekepino.coffee
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar