Pascal/Turbo Pascal - Ayuda sobre archivos en pascal

 
Vista:
sin imagen de perfil

Ayuda sobre archivos en pascal

Publicado por Jairo (4 intervenciones) el 10/08/2021 20:58:49
Buenos días a toda la comunidad, quisiera solicitar ayuda acerca de un programa sobre archivos que debo realizar. Se me ha pedido hacer un programa que registre las entradas de vehículos a un estacionamiento, llevando el control de la placa, hora y fecha de entrada. Al introducir una placa (alfanumérica) el programa debe desplegar por pantalla las veces que ese vehículo ha ingresado al estacionamiento con su respectiva fecha y hora. Si el vehículo no ha ingresado que permita almacenarlo. Ya he adelantado el código pero mi problema está cuando despliega la información pues solo muestra él registro de la primera vez que ingresó el vehículo y las otras entradas no las muestra. No sé cómo hacer para que vaya saltando de entrada en entrada y las vaya mostrando. Cualquier apoyo u ayuda sería bienvenida. Gracias.
Pd: la data se debe almacenar en un archivo físico
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

Ayuda sobre archivos en pascal

Publicado por David (224 intervenciones) el 11/08/2021 20:23:44
Pon aquí lo que tengas avanzado del código. Así será más fáicl poder ayudarte.
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
sin imagen de perfil

Ayuda sobre archivos en pascal

Publicado por Jairo (4 intervenciones) el 11/08/2021 22:31:40
saludos. Gracias por responder, ya he podido conseguir que me muestre las placas de los vehiculos con su respectiva fecha y hora, pero solo necesito que me muestre los registros de la placa en especifico que quiera consultas (y no todos) aca pego el codigo, y gracias de antemano por el apoyo:

{ programa para registrar la entrada de
autos a un estacionamiento por fecha
y hora }

program estacionamiento;
uses
crt;
const
archivo = 'archivo.dat';
type
autos = record
placa : string[80];
fec_ent : string[80];
hora : string[80];
end;

var
f : file of autos;
control : autos;

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(' ****** Registrar Datos ******');
writeln;
write(' Ingrese placa: ');
readln(control.placa);
write(' Ingrese fecha : ');
readln(control.fec_ent);
write(' Ingrese hora : ');
readln(control.hora);
writeln(' Pulse S para guardar [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,control);
close(f);
end
else
begin
rewrite(f);
seek(f,0);
write(f,control);
close(f);
end;
end;
end;

procedure busqueda_auto;
var
plc : string[80];
b_us : integer;
encon : boolean;
i :integer;
begin
if existearchivo = true then
begin
writeln(' Buscar placa ');
writeln;
write(' Ingrese placa : ');
readln(plc);
encon := false;
for b_us := 0 to filesize(f) - 1 do
begin
seek(f,b_us);
read(f,control);
if control.placa = plc then
begin
encon := true;
break;
end;
end;
if encon = true then
for b_us := 0 to filesize(f) - 1 do
begin
seek(f,b_us);
read(f,control);
writeln('Placa ',control.placa,' Fecha: ',control.fec_ent,' Hora ',control.hora);
end
else
writeln(' Placa no registrada ');
close(f);
writeln;
writeln(' [Pulse Una Tecla para continuar]');
readkey;
end
else
begin
writeln(' No se encuentran datos... [Pulse Una Tecla]');
readkey;
end;
end;


procedure menu;
var
sal : boolean;
tecla : char;
begin
sal := false;
repeat
clrscr;
writeln(' ***** Menu Principal *****');
writeln;
writeln(' 1 = Registrar placa');
writeln(' 2 = Buscar...');
writeln(' 3 = Salir');
writeln;
writeln(' >>> Elija Opcion <<<');
repeat
tecla := readkey;
until tecla in['1','2','3'];
clrscr;
case tecla of
'1' : entradadatos;
'2' : busqueda_auto;
'3' : sal := true;
end;
until sal = true;
end;

begin
clrscr;
menu;
clrscr;
end.
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
sin imagen de perfil

Ayuda sobre archivos en pascal

Publicado por Jairo (4 intervenciones) el 12/08/2021 00:48:09
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
{ programa para registrar la entrada de
  autos a un estacionamiento por fecha
  y hora }
 
program estacionamiento;
uses
    crt;
const
     archivo = 'archivo.dat';
type
    autos = record
             placa   : string[80];
             fec_ent : string[80];
             hora    : string[80];
            end;
 
   var
     f       : file of autos;
     control : autos;
 
    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('    ****** Registrar Datos ******');
      writeln;
      write('    Ingrese placa: ');
      readln(control.placa);
      write('    Ingrese fecha   : ');
      readln(control.fec_ent);
      write('    Ingrese hora    : ');
      readln(control.hora);
      writeln('   Pulse S para guardar [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,control);
           close(f);
        end
      else
          begin
             rewrite(f);
             seek(f,0);
             write(f,control);
             close(f);
          end;
      end;
   end;
 
    procedure busqueda_auto;
   var
     plc   : string[80];
     b_us  : integer;
     encon : boolean;
     i     :integer;
   begin
      if existearchivo = true then
      begin
        writeln('   Buscar placa ');
        writeln;
        write('     Ingrese placa : ');
        readln(plc);
        encon := false;
        for b_us := 0 to filesize(f) - 1 do
        begin
           seek(f,b_us);
           read(f,control);
           if control.placa = plc then
           begin
              encon := true;
              break;
           end;
        end;
        if encon = true then
           for b_us := 0 to filesize(f) - 1 do
            begin
              seek(f,b_us);
              read(f,control);
              writeln('Placa ',control.placa,' Fecha: ',control.fec_ent,' Hora ',control.hora);
             end
     else
        writeln('   Placa no registrada ');
        close(f);
        writeln;
        writeln('    [Pulse Una Tecla para continuar]');
        readkey;
      end
   else
      begin
         writeln('   No se encuentran datos...  [Pulse Una Tecla]');
         readkey;
      end;
   end;
 
 
   procedure menu;
   var
     sal    : boolean;
     tecla  : char;
     begin
        sal := false;
        repeat
           clrscr;
           writeln('    ***** Menu Principal *****');
           writeln;
           writeln('   1 = Registrar placa');
           writeln('   2 = Buscar...');
           writeln('   3 = Salir');
           writeln;
           writeln('   >>> Elija Opcion <<<');
         repeat
            tecla := readkey;
         until tecla in['1','2','3'];
         clrscr;
     case tecla of
       '1' : entradadatos;
       '2' : busqueda_auto;
       '3' : sal := true;
     end;
     until sal = true;
   end;
 
   begin
      clrscr;
      menu;
      clrscr;
   end.
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
sin imagen de perfil

Ayuda sobre archivos en pascal

Publicado por Jairo (4 intervenciones) el 12/08/2021 00:51:08
aca va el codigo, solo necesito saber como mostrar los datos de una sola placa en especifico y no todos. Gracias

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
{ programa para registrar la entrada de
  autos a un estacionamiento por fecha
  y hora }
 
program estacionamiento;
uses
    crt;
const
     archivo = 'archivo.dat';
type
    autos = record
             placa   : string[80];
             fec_ent : string[80];
             hora    : string[80];
            end;
 
   var
     f       : file of autos;
     control : autos;
 
    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('    ****** Registrar Datos ******');
      writeln;
      write('    Ingrese placa: ');
      readln(control.placa);
      write('    Ingrese fecha   : ');
      readln(control.fec_ent);
      write('    Ingrese hora    : ');
      readln(control.hora);
      writeln('   Pulse S para guardar [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,control);
           close(f);
        end
      else
          begin
             rewrite(f);
             seek(f,0);
             write(f,control);
             close(f);
          end;
      end;
   end;
 
    procedure busqueda_auto;
   var
     plc   : string[80];
     b_us  : integer;
     encon : boolean;
     i     :integer;
   begin
      if existearchivo = true then
      begin
        writeln('   Buscar placa ');
        writeln;
        write('     Ingrese placa : ');
        readln(plc);
        encon := false;
        for b_us := 0 to filesize(f) - 1 do
        begin
           seek(f,b_us);
           read(f,control);
           if control.placa = plc then
           begin
              encon := true;
              break;
           end;
        end;
        if encon = true then
           for b_us := 0 to filesize(f) - 1 do
            begin
              seek(f,b_us);
              read(f,control);
              writeln('Placa ',control.placa,' Fecha: ',control.fec_ent,' Hora ',control.hora);
             end
     else
        writeln('   Placa no registrada ');
        close(f);
        writeln;
        writeln('    [Pulse Una Tecla para continuar]');
        readkey;
      end
   else
      begin
         writeln('   No se encuentran datos...  [Pulse Una Tecla]');
         readkey;
      end;
   end;
 
 
   procedure menu;
   var
     sal    : boolean;
     tecla  : char;
     begin
        sal := false;
        repeat
           clrscr;
           writeln('    ***** Menu Principal *****');
           writeln;
           writeln('   1 = Registrar placa');
           writeln('   2 = Buscar...');
           writeln('   3 = Salir');
           writeln;
           writeln('   >>> Elija Opcion <<<');
         repeat
            tecla := readkey;
         until tecla in['1','2','3'];
         clrscr;
     case tecla of
       '1' : entradadatos;
       '2' : busqueda_auto;
       '3' : sal := true;
     end;
     until sal = true;
   end;
 
   begin
      clrscr;
      menu;
      clrscr;
   end.
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