Pascal/Turbo Pascal - Cómo trabajar con 2 archivos???

 
Vista:

Cómo trabajar con 2 archivos???

Publicado por faacu (3 intervenciones) el 18/10/2019 18:28:04
Hola gente!! Estoy haciendo un ejercicio pero me quedé trabado en el utimo item, que dice:

Ingresando un mes y un año y comprobando que dicha fecha exista en historia.dat, mostrar todos los cachorros del archivo mascotas.dat que deberán venir en dicha fecha, mostrando código de cachorro, nombre, dueño y mail para hacer las notificaciones .

Dejo lo que tengo hasta ahora, me falta ese solo procedimiento, pero no sé como preguntar por un campo de un X archivo y mostrar los datos de otro archivo

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
uses crt;
 
CONST ruta = 'C:\Users\Facu\Desktop\pascal\mascotas.dat' ;
      rutaH = 'C:\Users\Facu\Desktop\pascal\historia.dat' ;
 
type
    rMascota = record
                      cod: integer;
                      nombre: string[20];
                      duenio: string[35];
                      mail: string [40];
                end;
 
    rHistoria = record
                      cod: integer;
                      diaDeVisita: string [8]; {DDMMAAAA}
                      atencion: char; //(P: peluquería / V: veterianaria)
                      corte: char; // (S/N)
                      banio: char; // (S/N)
                      vacuna: string [25];
                      medicamento: string [40];
                      proxControl: string [6]; {MMAAAA}
                end;
 
var
   regM : rMascota;
   archM: file of rMascota;
 
   regH : rHistoria;
   archH: file of rHistoria;
 
   t, tec : char;
   cont, contador: integer;
 
procedure carga;
begin
     clrscr;
     writeln('CARGA DE DATOS');
     writeln;
     write('Codigo mascota: '); readln(regM.cod);
     write('Nombre mascota: '); readln(regM.nombre);
     write('Duenio: '); readln(regM.duenio);
     write('Mail: '); readln(regM.mail);
     writeln;
 
     writeln('¿Datos correctos? [S/N]');
     repeat
           t:= upcase(readkey);
     until t in ['S', 's', 'N', 'n'];
 
     if (t='s') or (t='S') then
        begin
             assign(archM, ruta);
             {$I-} reset (archM); {$I+}
             if ioresult <> 0 then
                begin
                     rewrite(archM);
                     seek(archM, 0);
                     write(archM, regM);
                     close(archM);
                end
                else
                  begin
                       seek (archM, filesize(archM));
                       write(archM, regM);
                       close(archM);
                  end;
        end
        else
            begin
               carga;
            end;
end;
 
procedure PELUQUERIA(codigo: integer);
var ok: boolean;
begin
        assign(archH,rutaH);
  {$I-} reset(archH); {$I+}
      if ioresult <> 0 then
      begin
         writeln('   Error de archivo, pulse una tecla  ');
         readkey;
      end
    else
       begin
          ok := false;
          for cont := 0 to filesize(archH) - 1 do
          begin
             seek(archH,cont);
             read(archH,regH);
             if regH.cod = codigo then
             begin
                close(archH);
                ok := true;
                break;
             end;
          end;
            if ok = true then
            begin
            // writeln('Nombre: ', regM.nombre);
             regH.cod := codigo;
             regH.atencion := 'P';
 
             write('Fecha (ddmmaaaa): ');
             readln(regH.diaDeVisita);
 
             writeln('Corte [s/n]: ');
             repeat
                   readln(regH.corte)
             until (regH.corte = 's') or (regH.corte = 'n');
 
             write('Banio (s/n): ');
             repeat
                   readln(regH.banio)
             until (regH.banio = 's') or (regH.banio = 'n');
 
 
             writeln();
             writeln('Atencion registrada!!');
             readkey;
 
            end  //if ok false
            else begin
                  writeln('Codigo no encontrado');
                  readkey;
             end;
      end; //ioresult
 
end;
 
procedure vete(c: integer);
var okk: boolean;
begin
        assign(archH,rutaH);
  {$I-} reset(archH); {$I+}
      if ioresult <> 0 then
      begin
         writeln('   Error de archivo, pulse una tecla  ');
         readkey;
      end
    else
       begin
          okk := false;
          for contador := 0 to filesize(archH) - 1 do
          begin
             seek(archH,contador);
             read(archH,regH);
             if regH.cod = c then
             begin
                close(archH);
                okk := true;
                break;
             end;
          end;
            if okk = true then
            begin
             regH.cod := c;
             regH.atencion := 'V';
 
             write('Fecha (ddmmaaaa): ');
             readln(regH.diaDeVisita);
             write('Nombre de la vacuna: ');
             readln(regH.vacuna);
 
             writeln('Medicamento? [S/N]');
             repeat
                   t := upcase(readkey);
             until t in['S','N','s','n'];
             if (t = 'S') or (t = 's') then
                begin
                     writeln('Nombre del medicamento: ');
                     readln(regH.medicamento);
                end;
 
             writeln('Habra proximo control? [S/N]');
             repeat
                   t := upcase(readkey);
             until t in['S','N','s','n'];
             if (t = 'S') or (t = 's') then
                begin
                     writeln('Ingrese fecha [mmaaaa]: ');
                     readln(regH.proxControl);
                end;
 
 
             writeln();
             writeln('Atencion registrada!!');
             readkey;
 
            end  //if ok false
            else begin
                  writeln('Codigo no encontrado');
                  readkey;
             end;
      end; //ioresult
end;
 
{procedure avisos;
var
begin
end; }
 
procedure menu;
var  sal : boolean;
     tecla: char;
     codi, co: integer;
begin
sal := false;
    repeat
       clrscr;
       writeln('  ****** MENU DE OPCIONES ******');
       writeln;
       writeln(' [1] = Carga Inicial');
       writeln(' [2] = Peluqueria');
       writeln(' [3] =  Veterinaria');
       writeln(' [4] =  Avisos de proximos controles');
       writeln(' [5] =  Salir');
       writeln;
       writeln('  <<<< ELIJA OPCION >>>>');
     repeat
        tecla := readkey;
     until tecla in ['1','2','3','4','5'];
 
     clrscr;
     case tecla of
        '1' : carga;
        '2' : begin
                   write('Ingrese codigo del cachorro: ');
                   readln(codi);
                   peluqueria(codi);
              end;
        '3' : begin
                   write('Ingrese codigo del cachorro: ');
                   readln(co);
                   vete(co);
              end;
       // '4' : AVISOS;
        '5' : sal := true;
     end;
 
   until sal = true;
end;
 
BEGIN
     menu;
 
readkey;
 
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