Código de Pascal/Turbo Pascal - La Agencia de Turismo Toursven

Imágen de perfil

La Agencia de Turismo Toursvengráfica de visualizaciones


Pascal/Turbo Pascal

Publicado el 24 de Febrero del 2016 por Salazarvalbuena
2.957 visualizaciones desde el 24 de Febrero del 2016
En este código se guardan los datos de los clientes para una Agencia Toursven. Este programa se maneja con ficheros, se puede ver el código rutinas para guardar datos, modificar, eliminar y consultar datos. Además, tiene una rutina sencilla para validar fecha con trystrtodate. Quizás no sea el mejor código pero espero que ha alguien le sea de ayuda y lo comparto. Gracias a este sitio web pude realizarlo.

Requerimientos

librerías de Pascal: sysutils,dateutils,crt;

Free Pascal
estrellaestrellaestrellaestrellaestrella(5)

Publicado el 24 de Febrero del 2016gráfica de visualizaciones de la versión: Free Pascal
2.958 visualizaciones desde el 24 de Febrero del 2016
estrellaestrellaestrellaestrellaestrella
estrellaestrellaestrellaestrella
estrellaestrellaestrella
estrellaestrella
estrella

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
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
{Elaborado por DANIEL RONDON C.I.22854574}
{COMPUTACION 1 UNA-ANZOATEGUI}
 
program turismotoursven;
 
uses
 
  sysutils,dateutils,crt;
  {las bibliotecas,sysutils y dateutilis,}
  {solucionan de una manera sencilla}
  {rutinas relacionadas con fechas}
 
const
  archivo  = 'DATOS.dat';
  temporal = 'TEMPO.dat';
 
type
  TElturista = record
  Numeropas : longint;       {numero de pasaporte}
  Nombreape : string[60];    {nombre y apellido}
  origenpas : char;          {origen de pasaporte}
    fechapas,                {Fecha Exp. pasaporte}
   fechavac,                 {Fecha Exp. certificado vacuna}
   fechadec: TDate;          {Fecha Exp. declaracion de impuestos}
end;
 
var
  f : file of TElturista;                 {Archivo maestro}
  datos,aux,cop: TElturista;              {auxiliares para guardar los datos}
  Rmarcado,registro,registro2 :integer;   {variables indice}
 
function existearchivo : boolean;
  begin
    assign(f,archivo);
    {$I-} reset(f); {$I+}
    if ioresult = 0 then
      existearchivo := true
    else
      existearchivo := false;
  end;
 
function Expedicion(fecha:TDate) : integer;
  begin
    DaysBetween(Date,fecha);
  end;
 
  {para la solucionar el problema de la vigencia de las fechas}
  {se utiliza daysbetween,date and Incyear recordando que }
  {un anho tiene 365 o 366 dias y dos anhos tiene 730 o 731 dias}
 
function anhos(ano:byte) : integer;
  begin
    DaysBetween(Date,Incyear(Date,-ano));
  end;
 
function existeregistro(var num:longint) : boolean;
  var
    encontrado: boolean;     {Determina la existencia de un registro}
  begin
    encontrado := false;
    for Registro := 0 to filesize(f) - 1 do
      begin
        seek(f,Registro);
        read(f,aux);
        if aux.Numeropas = num then
          begin
            encontrado := true;
            Rmarcado := Registro;
            break;
          end;
      end;
    if encontrado = true then
      existeregistro := true
    else
      existeregistro := false;
  end;
 
procedure guardardatos(var aux:TElturista);
  begin
          if existearchivo then
            begin
              seek(f,filesize(f));
            end
          else
            begin
              rewrite(f);
              seek(f,0);
            end;
              write(f,aux);
              close(f);
              clrscr;
              writeln(' Datos guardado Pulse una tecla');
              readkey;
  end;
 
procedure mensaje;
  begin
    writeln(' Nota: Antes de continuar es importante que lea esto: ');
    writeln;
    textcolor(11);
    writeln('   -El campo 1:Nombre y apellido, admite solo letras y espacios. ');
    writeln('   -El campo 2:Numero de pasaporte, admite solo numeros. ');
    writeln('   -El campo 3:Origen de pasaporte, admite solo una letra V/E. ');
    writeln('   -El formato de fecha en los campos 4,5 y 6 es: DD/MM/AAAA .  ');
    if Monthof(date) in [1..9] then
      writeln('           Alternativa 1: DD/','0', MonthOf(date),'/',YearOf(date)      )
    else
      writeln('           Alternativa 1: DD/','', MonthOf(date),'/',YearOf(date)      );
      writeln('           Alternativa 2: DD/MM/',YearOf(date),'      ');
      writeln('           Alternativa 3: DD/MM/20AA                 '     );
      textcolor(white);
      writeln;
      writeln('    Pulse [S] continuar [N] Volver al menu  ');
    end;
 
procedure pasaportevalido(var num:longint);
  var
    strnum:string;             {auxiliar del numero de pasaporte}
    valido : boolean;   {Booleano para validar el campo}
 
  begin
    repeat
      repeat
        readln(strnum);
        val(strnum,num);
        if num < 1 then
          begin
            textcolor(yellow);
            write('        *Por favor,introduzca solo numeros*       : ');
            textcolor(white);
          end;
       until num >= 1;
       valido := true;
       if existearchivo then
         begin
           if existeregistro(num) then
             begin
               valido := false;
               textcolor(yellow);
               writeln('        Este numero ya esta en el sistema,         ');
               write('          *vuelva a introducirlo*                 : ');
               textcolor(white);
             end;
           close(f);
         end;
    until (valido = true);
  end;
 
procedure origenvalido(var opcion:char);
  begin
         repeat
           opcion:= upcase(readkey);
         until opcion in['E','V'];
         writeln(opcion);
  end;
 
procedure fechavalida( var fecha:TDate);
  var
     valido:boolean;  {Booleano para validar el campo}
     strfecha:string;
  begin
      repeat
        ReadLn(strfecha);
        valido:=TryStrToDate(strfecha,fecha);
        if valido = false then
          begin
                         textcolor(12);
            writeln('       *por favor,fecha en formato DD/MM/AAAA*     ');
            if Monthof(date) in [1..9] then
              writeln('           Alternativa 1: DD/','0', MonthOf(date),'/',YearOf(date)      )
            else
              writeln('           Alternativa 1: DD/','', MonthOf(date),'/',YearOf(date)      );
              writeln('           Alternativa 2: DD/MM/',YearOf(date),'      ');
              writeln('           Alternativa 3: DD/MM/20AA                 '     );
            textcolor(yellow);
              Write('      Introduzca nuevamente  la fecha             : ');
            textcolor(white);
          end;
      until valido=true ;
      if fecha > incyear(date,50) then
        fecha := incyear(fecha,-100);
  end;
 
procedure mostrardatos(var aux:TElturista);
  begin
    with aux do
      begin
        writeln('   Nombre y Apellido               = ',upcase(Nombreape));
        writeln('   Numero de pasaporte             = ',numeropas);
        writeln('   Origen de pasaporte             = ',origenpas);
        writeln('   Fecha del pasaporte             = ',DatetoStr(fechapas));
        writeln('   Fecha Certificado de vacuna     = ',DatetoStr(fechavac));
        writeln('   Fecha Declaracion de impuestos  = ',DatetoStr(fechadec));
        writeln;
        if (((Expedicion(fechapas)> anhos(1)) and (Origenpas='V')) or
           ((Expedicion(fechapas) > anhos(2)) and (Origenpas='E')))
          or (Expedicion(fechavac) > anhos(1))
          or (Expedicion(fechadec) > anhos(1)) then
            writeln('  "RECAUDOS NO VIGENTES"');
      end;
  end;
 
procedure NombreYapellidovalido(var nomb:string);
type
  TAscii = set of #1..#255;
  var
    alfabeto,espacio:TAscii;
    valido : boolean;           {Booleano para validar el campo}
    caracter  : byte;
 
  begin
        alfabeto:=[#65..#90,#97..#122,#165..#166];
        espacio :=[#32];
        repeat
          valido := true;
          readln(nomb);
          for caracter := 1 to length(nomb) do
            begin
              if nomb[caracter] in alfabeto+espacio then
                 begin
                 end
              else
                begin
                  valido := false;
                  break;
                end;
              end;
              if valido = false then
                begin
                  textcolor(yellow);
                  write('     *Por favor,introduzca solo letras y espacio* : ');
                  textcolor(white);
                end;
         until valido = true;
  end;
 
 
procedure entradadatos;
  var
    opcion : char;         {tecla de opciones}
 
  begin
    clrscr;
    with datos do
      begin
        writeln('                                                   ',datetostr(Date));
        writeln('    ****** Entrada Datos turista ******');
        writeln;
        write('  1) Ingrese    Nombre    y    Apellido           : ');
        {En este campo solo se admiten letras y/o espacios}
        NombreYapellidovalido(nombreape);
 
         write('  2) Ingrese   Numero   pasaporte                 : ');
         {En este campo solo se admiten numeros}
         {Este campo no admitira 2 numeros de pasaporte iguales}
         pasaportevalido(numeropas);
 
         write('  3) Ingrese   Origen   del   pasaporte   [V/E]   : ');
         {V= Venezolano  E=Extranjero}
         origenvalido(origenpas);
 
         Write('  4) Ingrese   fecha   del   Pasaporte            : ');
         {La fecha debe ser en formato D/M/AA}
         fechavalida(fechapas);
 
         Write('  5) Ingrese fecha del certificado de vacuna      : ');
         {La fecha debe ser en formato D/M/AA}
         fechavalida(fechavac);
 
         Write('  6) Ingrese fecha de la declaracion de impuestos : ');
         {La fecha debe ser en formato D/M/AA}
         fechavalida(fechadec);
       end;
 
    clrscr;
    writeln('   Ha introducido los siguientes datos: ');
    writeln;
    mostrardatos(datos);
    writeln;
    writeln('   Desea Guardar Los Datos? ');
    writeln;
    writeln('    Pulse [S/N]');
      repeat
      opcion := upcase(readkey);
      until opcion in['S','N'];
      if opcion = 'S' then
         guardardatos(datos);
  end;
 
procedure busqueda;
  var
    num:longint;
  begin
    if not existearchivo  then
      begin
        writeln('  Error De Archivo O No Existe Pulse Una Tecla');
        readkey;
        exit;
      end
    else
      begin
        write('   Entre numero de pasaporte : ');
        readln(num);
        if existeregistro(num) then
          begin
            writeln;
            mostrardatos(aux);
          end
        else
          begin
            writeln;
            writeln('   No se encuentran datos del turista ');
          end;
        writeln;
        writeln('   Pulse una tecla   ');
        readkey;
        close(f);
      end;
  end;
 
procedure ordenar;
  {Existe un famoso metodo llamado Burbuja}
  {Con este metodo se ordenaran los datos por el numero de pasporte}
  begin
    if not existearchivo then
      begin
        writeln('  Error De Archivo O No Existe Pulse Una Tecla');
        readkey;
        exit;
      end
    else
      begin
       for registro := 0 to filesize(f) - 1 do
        for registro2 := registro + 1 to filesize(f) - 1 do
          begin
            seek(f,registro);
            read(f,datos);
            seek(f,registro2);
            read(f,Cop);
            if datos.Numeropas > Cop.Numeropas then
              begin
                Aux := datos;
                datos := Cop;
                Cop := Aux;
                seek(f,registro);
                write(f,datos);
                seek(f,registro2);
                write(f,Cop);
              end;
          end;
        close(f);
      end;
  end;
 
procedure modificacion;
   var
     opcion : char;           {tecla de opciones}
     num:longint;
 
    begin
     clrscr;
     if not existearchivo then
       begin
         writeln('  Error De Archivo O No Existe Pulse Una Tecla');
         readkey;
         exit;
       end
     else
       begin
         write('   Entre numero de pasaporte : ');
         readln(num);
         if existeregistro(num) then
           begin
             repeat
               clrscr;
               with aux do
                 begin
                   writeln('                                       ',Datetostr(Date));
                   writeln('  **** Modificacion De Datos ****');
                   writeln;
                   writeln('  Numero de pasaporte    ' ,numeropas);
                   writeln;
                   write(' [1] = Nombre y Apellido               ') ;textcolor(11);writeln(upcase(Nombreape));textcolor(white);
                   write(' [2] = Origen del pasaporte            ') ;textcolor(11);writeln(origenpas);textcolor(white);
                   write(' [3] = Fecha del pasaporte             ') ;textcolor(11);writeln(DatetoStr(fechapas));textcolor(white);
                   write(' [4] = Fecha Certificado vacuna        ') ;textcolor(11);writeln(DatetoStr(fechavac));textcolor(white);
                   write(' [5] = Fecha declaracion de impuestos  ') ;textcolor(11);writeln(DatetoStr(fechadec));textcolor(white);
                   writeln(' [6] = finalizar');
                   writeln;
                 end;
               repeat
                 opcion := readkey;
               until opcion in[#49..#54];
               with aux do
               case opcion of
                 #49 : begin
                         write('  Ingrese    Nombre    y    Apellido              : ');
                         NombreYapellidovalido(Nombreape);
                       end;
                 #50 : begin
                         write('  Ingrese   Origen   del   pasaporte   [V/E]      : ');
                         origenvalido(origenpas);
                       end;
                 #51 : begin
                         Write('  Ingrese   fecha   del   Pasaporte               : ');
                         fechavalida(fechapas);
                       end;
                 #52 : begin
                         Write('  Ingrese fecha del certificado de vacuna         : ');
                         fechavalida(fechavac);
                       end;
                 #53 : begin
                         Write('  Ingrese fecha de la declaracion de impuestos    : ');
                         fechavalida(fechadec);
                       end;
               end;
             until opcion = #54;
             seek(f,Rmarcado);
             write(f,aux);
           end
         else
           begin
             writeln('   Dato No Encontrado Pulse Una Tecla');
             readkey;
           end;
       close(f);
       end;
    end;
 
procedure anularegistro;
  var
           faux: file of TElturista; {Archivo auxiliar}
            opcion : char;             {tecla de opciones}
            num: longint;
 
  begin
    if not existearchivo  then
      begin
	writeln(' Error de Archivo o no existe Pulse Una Tecla');
        readkey;
        exit;
      end
    else
      begin
           write('   Entre numero de pasaporte : ');
           readln(num);
	   if existeregistro(num) then
	     begin
               writeln;
               mostrardatos(aux);
               writeln;
               writeln('  <<< Esta Seguro Que Desea Eliminar Este registro? [S/N] >>>');
	       repeat
		 opcion := upcase(readkey);
	       until opcion in['S','N'];
	       if opcion = 'S' then
	         begin
		   assign(faux,temporal);
		   rewrite(faux);
		   for registro := 0 to filesize(f) - 1 do
		     begin
		       seek(f,registro);
		       if registro <> Rmarcado then
			 begin
			   read(f,aux);
			   seek(faux,filesize(faux));
			   write(faux,aux);
			 end;
		     end;
		   close(f);
		   close(faux);
		   erase(f);
		   rename(faux,archivo);
                   clrscr;
                   writeln(' Datos eliminado Pulse una tecla');
                   readkey;
		 end;
	       if opcion = 'N' then
		 begin
		   close(f);
		 end;
	     end
	   else
	     begin
               writeln(' Datos no encontrado Pulse una tecla');
               readkey;
	       close(f);
	     end;
       end;
  end;
 
procedure mostrar;
  begin
   if not existearchivo  then
      begin
        exit;
      end
     else
      begin
        writeln('    <<< Listado Ordenado  >>> ');
        writeln;
        While not EOF(f) do
          begin
            read(f,datos);
            if datos.Numeropas <> 0 then
                begin
                writeln('    ',datos.Numeropas,' ',upcase(datos.Nombreape));
                end;
           end;
           close(f);
         writeln;
         writeln(' <<< Pulse Una Tecla Para Regresar >>>');
         readkey;
        end;
  end;
 
procedure contador;
  var
            vene,          {Contador de turistas venezolanos}
           extra,          {contador de turistas extranjeros}
           vacun,          {contador de turistas con fecha de vacuna vencida}
           impue,          {contador de turistas con fecha de declaracion vencida}
           recau:integer;  {contador de turistas con recaudos vigentes}
  begin
    if not existearchivo then
      begin
        writeln('  Error De Archivo O No Existe Pulse Una Tecla  ');
        readkey;
        exit;
      end
     else
      begin
        vene := 0;
        extra := 0;
        vacun := 0;
        impue := 0;
        recau := 0;
        While not EOF(f) do
          begin
            read(f,datos);
            with datos do
            if (Numeropas <> 0) then
              begin
               if (origenpas='V') then
                  inc(vene);
                if (origenpas='E') then
                  inc(extra);
                if (Expedicion(fechavac)>anhos(1)) then
                  inc(vacun);
                if (Expedicion(fechadec)>anhos(1)) then
                  inc(impue);
                if (((Expedicion(fechapas)<=anhos(1)) and (Origenpas='V')) or
                   ((Expedicion(fechapas)<=anhos(2)) and (Origenpas='E')))
                  and (Expedicion(fechavac)<=anhos(1))
                  and (Expedicion(fechadec)<=anhos(1)) then
                    inc(recau);
               end;
         end;
         clrscr;
         writeln('    <<< Datos>>>');
         writeln;
         WriteLn('  turistas venezolanos                  ',vene);
         WriteLn('  turistas extranjeros                  ',extra);
         WriteLn('  turistas con c. de vacuna vencido     ',vacun);
         WriteLn('  turistas con d. de impuestos vencido  ',impue);
         WriteLn('  turistas con Recaudos  vigentes       ',recau);
         close(f);
         writeln;
         writeln(' <<< Pulse Una Tecla Para Regresar >>>');
         readkey
    end;
  end;
 
procedure menu;
  var
    sal : boolean;  {booleano para salir del sistema}
    opcion : char;     {tecla de opciones}
  begin
    window(2,2,70,70);
    dateseparator := '/';
    shortdateformat := 'dd/mm/yyyy' ;
    sal := false;
    repeat
      clrscr;
      textcolor(white);
      writeln(' ***** Menu General *****');
      writeln;
      writeln('   1 = INCLUIR');
      writeln('   2 = MODIFICAR');
      writeln('   3 = ELIMINAR');
      writeln('   4 = REPORTE');
      writeln('   5 = SALIDA');
      writeln;
      writeln(' >>> Elija Opcion <<<');
      repeat
        opcion := readkey;
      until opcion in['1','2','3','4','5'];
        clrscr;
        case opcion of
          '1' : begin
                  mensaje;
                  repeat
                    opcion := upcase(readkey);
                  until opcion in['S','N'];
                    case opcion of
                      'S': begin clrscr;entradadatos;end;
                    end;
                 end;
          '2' :  modificacion;
          '3' :  anularegistro;
          '4' :begin
                 repeat
                   clrscr;
                   writeln(' Pulse L = LISTADO ORDENADO');
                   writeln(' Pulse C = CONSULTA');
                   writeln(' Pulse I = INFORMACION-CONTADORES');
                   writeln(' Pulse V = VOLVER AL MENU ');
                   writeln;
                   writeln('<< Elija una opcion >>');
                   repeat
                     opcion := upcase(readkey);
                   until opcion in['L','C','I','V'];
                     case opcion of
                       'L': begin clrscr;ordenar;mostrar;end;
                       'C': begin clrscr;busqueda; end;
                       'I': begin clrscr;Contador;end;
                     end;
                  until opcion = 'V';
                end ;
 
          '5' : sal := true;
         end;
    until sal = true;
  end;
 
 
begin
  menu;
end.



Comentarios sobre la versión: Free Pascal (5)

Imágen de perfil
24 de Febrero del 2016
estrellaestrellaestrellaestrellaestrella
Aquí está mi código es hastebin.

http://hastebin.com/nadekepino.coffee
Responder
Imágen de perfil
24 de Febrero del 2016
estrellaestrellaestrellaestrellaestrella
Aquí pueden verlo en modo solo texto.

http://hastebin.com/raw/nadekepino
Responder
25 de Mayo del 2016
estrellaestrellaestrellaestrellaestrella
execelente :)
Responder
4 de Julio del 2018
estrellaestrellaestrellaestrellaestrella
muuuuchas gracias muy bueno
Responder
10 de Abril del 2020
estrellaestrellaestrellaestrellaestrella
sugerencia: agrega strnum:string en var y cambia readln(num) por readln(strnum); val(strnum,num) en los procedure busqueda,modificacion y anularegistro.
Responder

Comentar la versión: Free Pascal

Nombre
Correo (no se visualiza en la web)
Valoración
Comentarios...
CerrarCerrar
CerrarCerrar
Cerrar

Tienes que ser un usuario registrado para poder insertar imágenes, archivos y/o videos.

Puedes registrarte o validarte desde aquí.

Codigo
Negrita
Subrayado
Tachado
Cursiva
Insertar enlace
Imagen externa
Emoticon
Tabular
Centrar
Titulo
Linea
Disminuir
Aumentar
Vista preliminar
sonreir
dientes
lengua
guiño
enfadado
confundido
llorar
avergonzado
sorprendido
triste
sol
estrella
jarra
camara
taza de cafe
email
beso
bombilla
amor
mal
bien
Es necesario revisar y aceptar las políticas de privacidad

http://lwp-l.com/s3446