Pascal/Turbo Pascal - ABM Pascal

 
Vista:
sin imagen de perfil

ABM Pascal

Publicado por Horacio (53 intervenciones) el 18/10/2012 18:56:09
Hola gente;quisiera si alguno me puede dar una mano con este ejercicio:

Altas y bajas
Cuando se producen altas y bajas se debe generar un nuevo archivo maestro con el mismo diseño que el original. Al terminar el proceso, el archivo original deberá ser eliminado.

2. Se dispone de un archivo maestro de empleados y de un archivo de altas:

Archivo maestro: Un registro por empleado
SECCIÓN
EMPLEADO
NOMBRE Y APELLIDO
CARGO
SUELDO BÁSICO

Archivo de altas: Uno o ningún registro por empleado
SECCIÓN
EMPLEADO
NOMBRE Y APELLIDO
CARGO
SUELDO BÁSICO


Aparear los archivos a fin de generar un archivo maestro actualizado, incorporando las altas. Contar e imprimir "ALTA ERRÓNEA" cuando el registro de alta ya existe en el archivo maestro.

Informar según la siguiente salida impresa:

Sección Empleado Nombre y Apellido Cargo Sueldo básico
XXXX XXXXX XXXXXXXXXXX XX XXXX,XX
XXXX XXXXX XXXXXXXXXXX XX ALTA ERRONEA


Total de altas realizadas: XXXX Erróneas: XXX

desde ya gracias.saludos
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

ABM Pascal

Publicado por ramon (2158 intervenciones) el 19/10/2012 13:54:10
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
{A ver si esto te ayuda}
 
 program empresa;
  uses
     crt, dos;
   type
        regmaestro = record
              SECCION : integer;
             EMPLEADO : integer;
      NOMBREYAPELLIDO : string[80];
                CARGO : string[40];
        SUELDOBASICO : real;
     end;
 
   var
     maestro : file of regmaestro;
     archivo : regmaestro;
     alta, erroralta : integer;
 
 
  procedure entradaempleados;
  var
    tee : char;
    cont : longint;
    travaj : regmaestro;
    repe : boolean;
  begin
      clrscr;
      writeln('**** Entrada Datos Empleado ****');
      writeln;
      write('    SECCION : ');
      readln(archivo.SECCION);
      write('    N§ Empleado : ');
      readln(archivo.EMPLEADO);
      write('    Nombre y Apellido : ');
      readln(archivo.NOMBREYAPELLIDO);
      write('    Cargo : ');
      readln(archivo.CARGO);
      write('    Sueldo Vasico : ');
      readln(archivo.SUELDOBASICO);
      travaj := archivo;
    assign(maestro,'Empleado.dat');
   {$I-} reset(maestro); {$I+}
   if ioresult <> 0 then
   begin
      rewrite(maestro);
      seek(maestro,0);
      write(maestro,archivo);
      close(maestro);
      alta := alta + 1;
    end
  else
     begin
        cont := 0;
        repe := false;
      repeat
        seek(maestro,cont);
        read(maestro,travaj);
        if archivo.EMPLEADO = travaj.EMPLEADO then
        begin
           clrscr;
           writeln('  ALTA ERRONEA El Empleado Existe Pulse [Enter]');
           erroralta := erroralta + 1;
           readln;
           close(maestro);
           exit;
        end
     else
         begin
         cont := cont + 1;
         end;
    until (cont > filesize(maestro) - 1) or (repe = true);
    if repe = false then
    begin
        seek(maestro,filesize(maestro));
        write(maestro,archivo);
        close(maestro);
        alta := alta + 1;
    end;
   end;
  end;
 
  procedure presentadatos;
  var
    emple : regmaestro;
    ct : longint;
    x, y : integer;
  begin
    ct := 0;
    assign(maestro,'Empleado.dat');
   {$I-} reset(maestro); {$I+}
   if ioresult <> 0 then
   begin
      writeln('  Error De Archivo Pulse [Enter]');
      readln;
      exit;
   end
 else
  begin
  x := 2;
  y := 1;
  gotoxy(x,y);write('Seccion  Empleado  Nombre y Apellido      Cargo',
  '           Sueldo basico');
  x := 5;
  y := 2;
  repeat
    seek(maestro,ct);
    read(maestro,emple);
    gotoxy(x,y);write(emple.SECCION);
    gotoxy(x + 6,y);write(emple.EMPLEADO);
    gotoxy(x + 16,y);write(emple.NOMBREYAPELLIDO);
    gotoxy(x + 39,y);write(emple.CARGO);
    gotoxy(x + 59,y);write(emple.SUELDOBASICO:0:2);
   y := y + 1;
   if y > 23 then
   begin
   y := 23;
   readkey;
   end;
   ct := ct + 1;
  until ct > filesize(maestro) - 1;
  gotoxy(x,y);write('Errores De Altas : ',erroralta);
  gotoxy(x,y + 1);write('Altas Realizadas = ',alta);
  close(maestro);
  readln;
  end;
 end;
 
  procedure vajasempleado;
  var
    vaja : regmaestro;
    apareo : file of regmaestro;
    ap, apa, conta : longint;
    tecla : char;
    nume : integer;
    encontre : boolean;
  begin
      clrscr;
      writeln('*** Baja De Empleado ***');
      writeln;
      write('Entre N§ Empleado : ');
      readln(nume);
     assign(maestro,'Empleado.dat');
   {$I-} reset(maestro); {$I+}
   if ioresult <> 0 then
   begin
       clrscr;
       writeln('   Error De Archivo Pulse [Enter]');
       readln;
       exit;
   end
  else
     begin
        conta := 0;
        encontre := false;
     repeat
         seek(maestro,conta);
         read(maestro,archivo);
         if archivo.EMPLEADO = nume then
         encontre := true
       else
         conta := conta + 1;
     until (conta > filesize(maestro) - 1) or (encontre = true);
     clrscr;
     writeln('<<< Anulando Registro Empleado N§ = ',archivo.EMPLEADO);
     writeln('<<< Con Nombre = ',archivo.NOMBREYAPELLIDO);
     writeln;
     writeln(' ****** Es Correcto [S/N] ******');
     repeat
         tecla := upcase(readkey);
    until tecla in['S','N'];
    if tecla = 'S' then
    begin
        apa := 0;
        ap := 0;
        assign(apareo,'tempo.dat');
        rewrite(apareo);
     repeat
         seek(maestro,apa);
         read(maestro,archivo);
         if archivo.EMPLEADO <> nume then
         begin
         seek(apareo,ap);
         write(apareo,vaja);
         ap := ap + 1;
         end;
     apa := apa - 1;
     until apa > filesize(maestro) - 1;
     close(maestro);
     close(apareo);
     erase(maestro);
     rename(apareo,'Empleado.dat');
    end
  else
     begin
       close(maestro);
     end;
   end;
  end;
 
  procedure modifica(n : longint);
  var
     ted : char;
     regtemp : regmaestro;
  begin
     seek(maestro,n);
     read(maestro,archivo);
     regtemp := archivo;
   repeat
     clrscr;
     writeln('*** Menu Modificaciones ****');
     writeln(' 1 = Seccion');
     writeln(' 2 = Empleado');
     writeln(' 3 = Nombre y Apellido');
     writeln(' 4 = Cargo');
     writeln(' 5 = Sueldo basico');
     writeln(' 6 = Nada');
     writeln;
     writeln('<<<< Elija Opcion >>>>>');
    repeat
        ted := readkey;
    until ted in['1','2','3','4','5','6'];
    case ted of
  '1' : begin
         clrscr;
         write('   Seccion : ');
         readln(regtemp.seccion);
         end;
  '2' : begin
         clrscr;
         write('   N§ Empleado : ');
         readln(regtemp.Empleado);
         end;
  '3' : begin
         clrscr;
         write('   Nombre y Apellido : ');
         readln(regtemp.NOMBREYAPELLIDO);
        end;
  '4' : begin
         clrscr;
         write('   Cargo : ');
         readln(regtemp.cargo);
        end;
  '5' : begin
         clrscr;
         write('   Sueldo basico : ');
         readln(regtemp.SUELDOBASICO);
        end;
    end;
    until ted = '6';
    clrscr;
    writeln('   Cambios Correctos [S/N]');
    repeat
        ted := upcase(readkey);
    until ted in['S','N'];
    if ted = 'S' then
    begin
       archivo := regtemp;
       seek(maestro,n);
       write(maestro,archivo);
    end;
   end;
 
  procedure modificaempleado;
  var
    num : integer;
    paso : longint;
    td : char;
    encon : boolean;
  begin
    assign(maestro,'Empleado.dat');
   {$I-} reset(maestro); {$I+}
   if ioresult <> 0 then
   begin
       clrscr;
       writeln('   Error De Archivo Pulse [Enter]');
       readln;
       exit;
   end
  else
    begin
    paso := 0;
    clrscr;
    writeln('<<<<< Modificar Datos Empleado >>>>>');
    writeln;
    write('   Entre N§ Empleado : ');
    readln(num);
    encon := false;
   repeat
      seek(maestro,paso);
      read(maestro,archivo);
      if archivo.EMPLEADO = num then
      encon := true
    else
      paso := paso + 1;
   until (paso > filesize(maestro) - 1) or (encon = true);
   if encon = true then
   begin
     modifica(paso);
     close(maestro);
   end
 else
    begin
        clrscr;
        writeln('  N§ De Empleado No Encontrado Pulse [Enter]');
        readln;
        close(maestro);
        exit;
    end;
   end;
  end;
 
 
  procedure menu;
  var
    sal : boolean;
    tec : char;
  begin
     sal := false;
     erroralta := 0;
     alta := 0;
   repeat
      clrscr;
      writeln(' **** Menu General ****');
      writeln;
      writeln('  1 = Entrada Empleado');
      writeln('  2 = Anular Empleado');
      writeln('  3 = Presenta Datos');
      writeln('  4 = Modifica Datos Empleado');
      writeln('  5 = Salir');
      writeln;
      writeln(' <<< Eloja Opcion >>>');
    repeat
       tec := readkey;
    until tec in['1','2','3','4','5'];
   case tec of
 '1' : begin clrscr; entradaempleados; end;
 '2' : begin clrscr; vajasempleado; end;
 '3' : begin clrscr; presentadatos; end;
 '4' : begin clrscr; modificaempleado; end;
 '5' : 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
1
Comentar
sin imagen de perfil

ABM Pascal

Publicado por Horacio (53 intervenciones) el 19/10/2012 15:48:43
otra vez Gracias Ramon,en este caso el procedimiento que implementaste realiza una baja fisica? si podrias explicarme como seria una baja logica?saludos
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

ABM Pascal

Publicado por ramon (2158 intervenciones) el 19/10/2012 19:35:01
La baja lógica mantiene siempre los datos pero el programa no debe de leer excepto que se
deseara reactivar en algún momento después.
Se realiza macando el registro por ejemplo archivo.EMPLEADO con *EMPLEADO y al leer `
para presentar o manejar lo ignora.
Pero esto crea archivos muy grandes y con mucha basura que pueden causar errores.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar