Pascal/Turbo Pascal - uso de Case para incrementar o disminuir variables

 
Vista:
sin imagen de perfil

uso de Case para incrementar o disminuir variables

Publicado por ELIAS (45 intervenciones) el 20/11/2012 20:28:43
Ayuda con Pascal. Procedure Modificar alumnos dependencia...


Debo mostrar un reporte que totalice el numero de alumnos inscritos en 1 de 6 dependencias (centros de estudio), eso lo hice, sin embargo hay un procedure para modificar datos y trasladar al estudiante de un centro a otro, cómo puedo hacer para incrementar en uno la variable de un centro de estudio, y borrar 1 de cualquiera de las dependencias donde se encontraba inscrito originalmente? Gracias...
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

uso de Case para incrementar o disminuir variables

Publicado por ramon (2158 intervenciones) el 21/11/2012 16:49:31
Primero pascal no permite modificar el tamaño de sus variables una vez definidas en un programa,
Segundo como as definido las variables ejemplo:
1
2
3
4
5
6
7
8
9
10
11
type
      reg =  record
              clase : char;
             alucno : integer;
         end;
 var
     alucno :  array[1..x] of integer;  {entonces amplia a 3 o 4 mas de las  que tengas como max entradas y ello te resolverá el problema}
      {como archivo}
   alucno : file of reg;   {sin problema anula e ingresa en el otro registro}
 
     tercero me puedes pasar lo que as echo para poder saber como 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

uso de Case para incrementar o disminuir variables

Publicado por elias (45 intervenciones) el 21/11/2012 18:04:26
Gracias, transcribo el código...el punto importante es la modificación del Centro de Estudio, y que el cambio se aprecie en el reporte...

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
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
Program TRABAJO;
uses CRT, printer;
const
Max = 1000;
ubicacion='C:\TRABAJO.dat';
 
Type
Registro=Record
Nom:String [30];
Ced: String [8];
Carnet:String;
Sexo:String;
Edad: integer;
Dir:String;
Tel:String [11];
CentroEst: integer;
Muj: integer;
Homb: integer;
May: integer;
Capi: integer;
Bar: integer;
Meri: integer;
Zuli: integer;
NvaE: integer;
Falc: integer;
 
Eliminar:Boolean;
End;
 
ListaEstu = array [1..Max] of Registro;
Archivo= File of Registro;
 
Var
i, j, anio, c, entero, code, hombres, mujeres, mayores, numero, error, capital, barquisimeto, merida, zulia, nuevaesparta, falcon: integer;
sal: Char;
Lista : ListaEstu;
contadorlapso : byte;
lapso: string[6];
f: file of registro;
datos: registro;
 
Procedure SumaContadorHM;
var
hombres, mujeres: integer;
begin
hombres := 0;
mujeres := 0;
End;
 
Procedure contadoredad;
var
mayores, Edad: integer;
begin
mayores := 0;
End;
 
 
Procedure PulsarUnaTecla;
var
Car  : char;
begin
GotoXY (25,23);
WriteLn ('pulsar cualquier tecla para continuar');
Car := Readkey;
ClrScr
End; { PulsarUnaTecla }
 
 
Procedure ContadorCE;
begin
capital := 0;
barquisimeto := 0;
merida := 0;
zulia := 0;
nuevaesparta := 0;
falcon := 0;
End;
 
 
Procedure ordenaarchivo;
var
dato2, temp : registro;
v, n : longint;
begin
assign(f,ubicacion);
{$I-} reset(f); {$I+}
if ioresult <> 0 then
begin
WriteLn('   PULSE [Enter]');
readln;
End
else
begin
for v := 0 to filesize(f) - 1 do
for n := filesize(f) - 1 downto v + 1 do
begin
seek(f,v);
read(f,datos);
seek(f,n);
read(f,dato2);
if datos.Ced > dato2.Ced then
begin
temp := datos;
datos := dato2;
dato2 := temp;
seek(f,v);
write(f,datos);
seek(f,n);
write(f,dato2);
End;
End;
End;
close(f);
End;
 
 
 
Procedure Incluir(Var Arch:Archivo);
Var Reg:Registro;
c, u, i, j: integer;
Ced:String;
Encontre:Boolean;
Op:Char;
begin
i := c;
while contadorlapso < 1 do
begin
GotoXY(20,19); WriteLn('Introduzca Año de Estudio: ');
GotoXY(20,20);readln(anio);
GotoXY(20,21); WriteLn('Introduzca Lapso Academico: ');
GotoXY(20,22);readln(lapso);
contadorlapso:=contadorlapso+1;
End;
clrscr;
i:=i+1;
c:=i;
WriteLn('**************** UNIVERSIDAD ****************');
WriteLn;
GotoXY  (17, 3);WriteLn('******************** INCLUIR ********************');
WriteLn;
Repeat
begin
CLRSCR;
Repeat
GotoXY  (20, 5);Write('1º.- Verificar Cedula:  ');
ReadLn(Ced);
val (Ced[7], numero, error);
until error= 0;
GotoXY  (10, 7);WriteLn('El numero de Cedula  '    , Ced ,   '  parece que tiene un formato valido');
Reset(Arch);
Encontre:=False;
While Not Eof(Arch) And (Not Encontre) Do
begin
Read(Arch, Reg);
If (Reg.Ced = Ced) And (Not Reg.Eliminar)
Then Encontre:=True;
End;
If Encontre
then begin
Seek(Arch, FilePos(Arch)-1);
GotoXY  (20, 21);Write ('-------La Cedula ya fue Registrada-------');
GotoXY  (20, 23);WriteLn('***** Presione ENTER para continuar *****');
ReadKey;
EXIT;
End;
Close(Arch);
End;
CLRSCR;
WriteLn('**************** LA UNIVERSIDAD NACIONAL EXPERIMENTAL ASUNCION ****************');
WriteLn;
GotoXY  (17, 3);WriteLn('******************** INCLUIR ********************');
WriteLn;
GotoXY (25, 10); WriteLn('PROCEDA A REGISTRAR ESTUDIANTE');
Repeat
WriteLn;
Write('           Ingrese Cedula:   ');
ReadLn(Reg.ced);
val (Reg.Ced[7], numero, error);
until error= 0;
WriteLn('El numero de Cedula  '    , Reg.Ced ,   '  parece ser valida, presione Enter para continuar');
readkey;
WriteLn;
Repeat
Write('           Ingrese Numero de Carnet:   ');
ReadLn(Reg.Carnet);
val (Reg.Carnet[5], numero, error);
until error= 0;
WriteLn('El numero de Carnet  '    , Reg.Carnet ,   '  parece ser valido, presione Enter para continuar');
readkey;
WriteLn;
Repeat
Write('           Ingrese Nombres y Apellidos:   ');
ReadLn(Reg.Nom);
if Reg.Nom= '' then
WriteLn('Debe Escribir el Nombre del Estudiante');
until
Reg.Nom <> '';
Repeat
Write('           Ingrese Sexo del Estudiante (M/F, en MAYÚSCULA): ');
ReadLn(Reg.Sexo);
Reg.Homb:=hombres;
Reg.Muj:=mujeres;
if  (Reg.Sexo > 'M') or (Reg.Sexo < 'F') then
WriteLn ('Solo Indique M para Masculino o F para Femenino en MAYÚSCULA');
until  (Reg.Sexo = 'M') or (Reg.Sexo = 'F');
begin
SumaContadorHM;
End;
begin
if Upcase(Reg.sexo)='M' then
begin
hombres:= hombres + 1;
Reg.Homb:=hombres;
End;
if Upcase(Reg.Sexo)='F' then
begin
mujeres:= mujeres + 1;
Reg.Muj:=mujeres;
End;
End;
Write('           Ingrese Edad del Estudiante :   ');
{$I-} {Desactivacion de la directiva error en pascal}
ReadLn(Reg.Edad);
WHILE  IOResult <> 0 DO
begin
WriteLn('Debe Ingresar la Edad del Estudiante');
Write('Ingrese Edad del Estudiante :   ');
ReadLn(Reg.Edad);
End;
{$I+} {Activacion de la directiva error en pascal}
begin
contadoredad;
End;
begin
if ( Reg.Edad >= 30 ) then
begin
mayores:= mayores + 1;
Reg.May:=mayores;
End;
End;
Repeat
Write('           Ingrese Direccion :   ');
ReadLn(Reg.dir);
if Reg.dir= '' then
WriteLn('Debe Escribir la Direccion del Estudiante');
until
(Reg.dir <> '');
Repeat
Write('           Ingrese Telefono :   ');
ReadLn(Reg.tel);
val (Reg.tel[11], numero, error);
until error= 0;
WriteLn('Telefono  '    , Reg.tel ,   '  registrado, presione Enter para continuar');
Repeat
Write('           Ingrese Centro de Estudio:   ');
Write('1.CAPITAL, 2.BARQUISIMETO, 3.MERIDA, 4.ZULIA, 5.NVA ESPARTA, 6.FALCON: ');
readLn(Reg.CentroEst);
until Reg.CentroEst in [1..6];
case Reg.CentroEst of
 
1 : Write ('Capital');
2 : Write ('Barquisimeto');
3 : Write ('Merida');
4 : Write ('Zulia');
5 : Write ('Nueva Esparta');
6 : Write ('Falcon');
else
Write ('Opcion Invalida');
End;
 
case Reg.CentroEst of
1 : capital:=capital+1;
2 : barquisimeto:=barquisimeto+1;
3 : merida:=merida+1;
4 : zulia:=zulia+1;
5 : nuevaesparta:=nuevaesparta+1;
6 : falcon:=falcon+1;
else
End;
 
Reg.Capi:=capital;
Reg.Bar:=barquisimeto;
Reg.Meri:=merida;
Reg.Zuli:=zulia;
Reg.NvaE:=nuevaesparta;
Reg.Falc:=falcon;
WriteLn;
 
 
Reg.Eliminar:=False;
Reset(Arch);
If FileSize(Arch)<>0
Then Seek(Arch, FileSize(Arch));
Write(Arch, Reg);
WriteLn('             Desea agregar otro Estudiante [S/N]');
Repeat
sal := upcase(readkey);
until sal in['N','S'];
until sal = 'N';
clrscr;
Close(Arch);
WriteLn;
GotoXY(10,11); WriteLn('***** Presione ENTER para volver a Menu Principal *****');
Readkey;
End;
 
 
Procedure Eliminar(Var Arch:Archivo);
Var
Reg:Registro;
Ced:String;
Encontre:Boolean;
begin
GotoXY(20,20);Write('Ingrese Cedula del estudiante a borrar : ');
ReadLn(Ced);
Reset(Arch);
Encontre:=False;
While Not Eof(Arch) And (Not Encontre) Do
begin
Read(Arch, Reg);
If (Reg.Ced = Ced) And (Not Reg.Eliminar)
Then Encontre:=True;
End;
If Encontre
then begin
Seek(Arch, FilePos(Arch)-1);
Reg.Eliminar:=True;
begin
if Upcase(Reg.sexo)='M' then
begin
hombres:= hombres - 1;
Reg.Homb:=hombres;
End;
if Upcase(Reg.sexo)='F' then
begin
mujeres:= mujeres - 1;
Reg.Muj:=mujeres;
End;
End;
begin
if ( Reg.Edad >= 30 ) then
begin
mayores:= mayores - 1;
Reg.May:=mayores;
End;
End;
 
 
GotoXY  (33, 22);
Write ('Registro Borrado');
PulsarUnaTecla;
 
Write(Arch, Reg);
End;
Close(Arch);
End;
 
 
 
 
Procedure Modif(Var Arch:Archivo);
Var
Reg:Registro;
Ced:String;
Encontre:Boolean;
Op:Char;
j:integer;
 
begin
GotoXY(20,20); Write('Ingrese Cedula a Modificar : ');
ReadLn(Ced);
Reset(Arch);
Encontre:=False;
While Not Eof(Arch) And (Not Encontre) Do
begin
Read(Arch, Reg);
If (Reg.Ced = Ced) And (Not Reg.Eliminar)
Then Encontre:=True;
End;
If Encontre
then begin
Seek(Arch, FilePos(Arch)-1);
GotoXY  (33, 22);
Write ('Registro encontrado');
PulsarUnaTecla;
Repeat
ClrScr;
 
WriteLn('******* MODIFICACION *******');
WriteLn;
WriteLn('1-Cedula : ', Reg.Ced);
WriteLn('2-Carnet : ', Reg.Carnet);
WriteLn('3-Nombres : ', Reg.Nom);
WriteLn('4-Sexo   : ', Reg.Sexo);
WriteLn('5-Edad   : ', Reg.Edad);
WriteLn('6-Direccion : ', Reg.Dir);
WriteLn('7-Telefono : ', Reg.Tel);
WriteLn('8-Centro Estudio : ', Reg.CentroEst);
WriteLn('9-Finalizar');
WriteLn('0-Cancelar');
Repeat
Op:=ReadKey;
 
Until (Op >= '0') And (Op <= '9');
 
Case Op Of
'1':begin
Write('Ingrese Cedula :');
ReadLn(Reg.Ced);
End;
 
'2':begin
Write('Ingrese nuevo Carnet :');
ReadLn(Reg.Carnet);
End;
 
'3':begin
Write('Ingrese Nombres y Apellidos :');
ReadLn(Reg.Nom);
End;
 
'4':begin
Write('Modifique Sexo Estudiante:');
ReadLn(Reg.Sexo);
Reg.Homb:=hombres;
Reg.Muj:=mujeres;
 
begin
if Upcase(Reg.sexo)='M' then
begin
hombres:= hombres + 1;
Reg.Homb:=hombres;
mujeres:= mujeres - 1;
Reg.Muj:=mujeres;
End;
if Upcase(Reg.sexo)='F' then
begin
mujeres:= mujeres + 1;
Reg.Muj:=mujeres;
hombres:= hombres - 1;
Reg.Homb:=hombres;
End;
End;
End;
 
'5':begin
Write('Modifique Edad Estudiante:');
ReadLn(Reg.Edad);
 
begin
if ( Reg.Edad >= 30 ) then
begin
mayores:= mayores + 1;
End;
begin
if ( Reg.Edad <= 29 ) then
begin
mayores:= mayores - 1;
End;
End;
End;
End;
 
 
'6':begin
Write('Ingrese nueva Direccion :');
ReadLn(Reg.Dir);
End;
 
'7':begin
Write('Ingrese nuevo Telefono :');
ReadLn(Reg.Tel);
End;
 
'8':begin
Repeat
Write('Ingrese nuevo Centro Estudio :');
Write('1.CAPITAL, 2.BARQUISIMETO, 3.MERIDA, 4.ZULIA, 5.NVA ESPARTA, 6.FALCON :  ');
ReadLn(Reg.CentroEst);
 
until Reg.CentroEst in [1..6];
 
case Reg.CentroEst of
 
1 : WriteLn ('Capital');
2 : WriteLn ('Barquisimeto');
3 : WriteLn ('Merida');
4 : WriteLn ('Zulia');
5 : WriteLn ('Nueva Esparta');
6 : WriteLn ('Falcon');
else
WriteLn ('Opcion Invalida');
End;
 
 
 
{DESDE AQUI PROCESO DE MODIFICAR....QUE RESTE 1 A UN CENTRO DE ESTUDIO Y SUME AL NUEVO CENTRO DONDE SE TRASLADA ESTUDIANTE}
 
 
 
 
Reg.Capi:=capital;
Reg.Bar:=barquisimeto;
Reg.Meri:=merida;
Reg.Zuli:=zulia;
Reg.NvaE:=nuevaesparta;
Reg.Falc:=falcon;
End;
End;
 
Until (Op = '0') Or (Op = '9');
 
If Op ='0'
then Exit;
 
If Op='9'
Then Write(Arch, Reg);
 
GotoXY  (27, 14);
Write ('Edicion del Registro Finalizado');
PulsarUnaTecla;
End;
 
Close(Arch);
End;
 
Procedure Consult(Var Arch:Archivo);
Var
Reg:Registro;
Ced:String;
Encontre:Boolean;
Op:Char;
begin
GotoXY(20,20); Write('Ingrese Cedula:  ');
ReadLn(Ced);
Reset(Arch);
Encontre:=False;
While Not Eof(Arch) And (Not Encontre) Do
begin
Read(Arch, Reg);
If (Reg.Ced = Ced) And (Not Reg.Eliminar)
Then Encontre:=True;
End;
If Encontre
then begin
Seek(Arch, FilePos(Arch)-1);
GotoXY  (33, 22);
Write ('Registro encontrado');
PulsarUnaTecla;
ClrScr;
 
GotoXY(28,3);WriteLn('******* CONSULTA *******');
WriteLn;
GotoXY(28,5);WriteLn('Cedula : ', Reg.Ced);
GotoXY(28,6);WriteLn('Carnet : ', Reg.Carnet);
GotoXY(28,7);WriteLn('Nombre : ', Reg.Nom);
GotoXY(28,8);WriteLn('Sexo   : ', Reg.Sexo);
GotoXY(28,9);WriteLn('Edad   : ', Reg.Edad);
GotoXY(28,10);WriteLn('Direccion : ', Reg.Dir);
GotoXY(28,11);WriteLn('Telefono : ', Reg.Tel);
GotoXY(28,12);WriteLn('Centro Estudio : ', Reg.CentroEst);
GotoXY(7,13);WriteLn('1.CAPITAL, 2.BARQUISIMETO, 3.MERIDA, 4.ZULIA, 5.NVA ESPARTA, 6.FALCON');
PulsarUnaTecla;
End;
Close(Arch);
End;
 
 
 
 
 
 
Procedure Listar(Var Arch:Archivo);
Var Reg:Registro;
j: longint;
begin
ordenaarchivo;
{$I-} Reset(Arch); {$I+}
while Not Eof(Arch) Do
begin
Read(Arch, Reg);
If Reg.Eliminar = FALSE
then
begin
CLRSCR;
for j := 0 to filesize(Arch) - 1 do
begin
seek (Arch,j);
read (Arch,Reg);
 
If Reg.Eliminar = FALSE
then
WriteLn(Reg.ced,'       ',Reg.carnet,'      ',Reg.nom,'      ',Reg.sexo,'      ',Reg.edad);
End;
End;
End;
Close(Arch);
WriteLn;
WriteLn('                    ***** Presione ENTER para continuar *****');
ReadKey;
End;
 
 
Procedure Reporte(Var Arch:Archivo);
Var Reg:Registro;
 
begin
 
{$I-} Reset(Arch); {$I+}
while Not Eof(Arch) Do
begin
Read(Arch, Reg);
If Reg.Eliminar = FALSE
then
 
begin
CLRSCR;
 
WriteLn('**************** UNIVERSIDAD ****************');
WriteLn;
WriteLn('                     *** RELACION DE ESTUDIANTES INSCRITOS ***');
WriteLn;
WriteLn('                     AÑO:',anio,'........................','LAPSO:',lapso);
WriteLn;
WriteLn;
WriteLn('        LA CANTIDAD DE ESTUDIANTES MUJERES ES:.......................',Reg.muj);
WriteLn;
WriteLn('        LA CANTIDAD DE ESTUDIANTES HOMBRES ES:.......................',Reg.homb);
WriteLn;
WriteLn('        CANTIDAD DE ESTUDIANTES MAYORES DE 30 AÑOS:..................',Reg.may);
WriteLn;
WriteLn('        NUMERO DE ESTUDIANTES DEL CENTRO ESTUDIO REGION CAPITAL:.....',Reg.capi);
WriteLn;
WriteLn('        NUMERO DE ESTUDIANTES DEL CENTRO ESTUDIO BARQUISIMETO  :.....',Reg.bar);
WriteLn;
WriteLn('        NUMERO DE ESTUDIANTES DEL CENTRO ESTUDIO MERIDA        :.....',Reg.meri);
WriteLn;
WriteLn('        NUMERO DE ESTUDIANTES DEL CENTRO ESTUDIO ZULIA         :.....',Reg.zuli);
WriteLn;
WriteLn('        NUMERO DE ESTUDIANTES DEL CENTRO ESTUDIO NUEVA ESPARTA :.....',Reg.NvaE);
WriteLn;
WriteLn('        NUMERO DE ESTUDIANTES DEL CENTRO ESTUDIO FALCON        :.....',Reg.falc);
 
End;
End;
Close(Arch);
WriteLn;
WriteLn('                    ***** Presione ENTER para continuar *****');
ReadKey;
End;
 
 
Var
Arch:Archivo;
Opcion:Char;
begin
Assign(Arch, ubicacion);
{$i-}
Reset(Arch);
{$I+}
If IOResult <> 0
Then ReWrite(Arch);
Close(Arch);
Repeat
ClrScr;
WriteLn('  ************** UNIVERSIDAD **************');
WriteLn;
WriteLn('                      ************** MENU **************');
WriteLn;
if contadorlapso= 1 then
begin
WriteLn('  AÑO:   ',anio);
WriteLn('  lapso: ',lapso);
End;
WriteLn;
GotoXY(20,5);  WriteLn('1 - Incluir');
GotoXY(20,7);  WriteLn('2 - Consultar');
GotoXY(20,9);  WriteLn('3 - Modificar');
GotoXY(20,11);  WriteLn('4 - Eliminar');
GotoXY(20,13);  WriteLn('5 - Listar');
GotoXY(20,15); WriteLn('6 - Reporte (Relacion de Estudiantes Inscritos)');
GotoXY(20,17); WriteLn('0 - Salir');
WriteLn;
Repeat
Opcion:=ReadKey;
 
Until (Opcion >= '0') And (Opcion <= '6');
Case Opcion of
'1': Incluir(Arch);
'2': Consult(Arch);
'3': Modif(Arch);
'4': Eliminar(Arch);
'5': Listar(Arch);
'6': Reporte(Arch);
End;
Until Opcion = '0';
 
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

uso de Case para incrementar o disminuir variables

Publicado por ramon (2158 intervenciones) el 21/11/2012 21:41:17
A ver cuando modificas un registro te posicionas en el cuando cambias su contenido cuando lo
guardas guardas los cambios que realices en el por lo cual ya as anulado uno y puesto el
otro en su lugar.

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
Procedure Modif(Var Arch:Archivo);
Var
Reg:Registro;
Ced:String;
Encontre:Boolean;
Op:Char;
j:integer;
 
begin
GotoXY(20,20); Write('Ingrese Cedula a Modificar : ');
ReadLn(Ced);
Reset(Arch);
Encontre:=False;
While Not Eof(Arch) And (Not Encontre) Do
begin
Read(Arch, Reg);
If (Reg.Ced = Ced) And (Not Reg.Eliminar)
Then Encontre:=True;
End;
If Encontre
then begin
Seek(Arch, FilePos(Arch)-1);
GotoXY  (33, 22);
Write ('Registro encontrado');
 
{Tu problema esta en que la operación [Not Eof(Arch) And (Not Encontre) ] no te facilita
  la dirección de cambio}
 
prueba esto:
  var
      contador  : longint;
 
   contador := 0;
 repeat
         seek(Arch, contador):
          read(Arch,Reg);
        if reg.Ced = Ced then
         encontrao := true
     else
           contador := contador  + 1;
    until (contador > filesize(arch)  - 1) or (encontrao = true);
    if  encontrao = true then
    begin
           A qui  cambia lo que sea y luego
           seek(Arch, contador):
           write(Arch,reg);
     El registro se cambio  pero ojo no esta seguro asta no realizar [ close(arch).
    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

uso de Case para incrementar o disminuir variables

Publicado por ELIAS (45 intervenciones) el 21/11/2012 21:57:21
Amigo, pero en el reporte cuando totalice los estudiantes por centro de estudio se vera reflejado el cambio? el código que me envías sustituye el actual en el procedure Modif?
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

uso de Case para incrementar o disminuir variables

Publicado por ELIAS (45 intervenciones) el 21/11/2012 22:16:16
Intente con este cambio pero no me ejecuta, ¿me falto algo?

Procedure Modif(Var Arch:Archivo);
Var
Reg:Registro;
Ced:String;
Encontre:Boolean;
Op:Char;
j:integer;
contador : longint;

begin
GotoXY(20,20); Write('Ingrese Cedula a Modificar : ');
ReadLn(Ced);
Reset(Arch);
Encontre:=False;
contador := 0;
repeat
seek(Arch, contador);
read(Arch,Reg);
if Reg.Ced = Ced then Encontre := true
else
contador := contador + 1;
until (contador > filesize(arch) - 1) or (Encontre = true);
if Encontre = true then
begin

WriteLn('******* MODIFICACION *******');
WriteLn;
WriteLn('1-Cedula : ', Reg.Ced);
WriteLn('2-Carnet : ', Reg.Carnet);
WriteLn('3-Nombres : ', Reg.Nom);
WriteLn('4-Sexo : ', Reg.Sexo);
WriteLn('5-Edad : ', Reg.Edad);
WriteLn('6-Direccion : ', Reg.Dir);
WriteLn('7-Telefono : ', Reg.Tel);
WriteLn('8-Centro Estudio : ', Reg.CentroEst);
WriteLn('9-Finalizar');
WriteLn('0-Cancelar');
Repeat
Op:=ReadKey;

Until (Op >= '0') And (Op <= '9');

Case Op Of
'1':begin
Write('Ingrese Cedula :');
ReadLn(Reg.Ced);
End;

'2':begin
Write('Ingrese nuevo Carnet :');
ReadLn(Reg.Carnet);
End;

'3':begin
Write('Ingrese Nombres y Apellidos :');
ReadLn(Reg.Nom);
End;

'4':begin
Write('Modifique Sexo Estudiante:');
ReadLn(Reg.Sexo);
Reg.Homb:=hombres;
Reg.Muj:=mujeres;

begin
if Upcase(Reg.sexo)='M' then
begin
hombres:= hombres + 1;
Reg.Homb:=hombres;
mujeres:= mujeres - 1;
Reg.Muj:=mujeres;
End;
if Upcase(Reg.sexo)='F' then
begin
mujeres:= mujeres + 1;
Reg.Muj:=mujeres;
hombres:= hombres - 1;
Reg.Homb:=hombres;
End;
End;
End;

'5':begin
Write('Modifique Edad Estudiante:');
ReadLn(Reg.Edad);

begin
if ( Reg.Edad >= 30 ) then
begin
mayores:= mayores + 1;
End;
begin
if ( Reg.Edad <= 29 ) then
begin
mayores:= mayores - 1;
End;
End;
End;
End;


'6':begin
Write('Ingrese nueva Direccion :');
ReadLn(Reg.Dir);
End;

'7':begin
Write('Ingrese nuevo Telefono :');
ReadLn(Reg.Tel);
End;

'8':begin
Repeat
Write('Ingrese nuevo Centro Estudio :');
Write('1.CAPITAL, 2.BARQUISIMETO, 3.MERIDA, 4.ZULIA, 5.NVA ESPARTA, 6.FALCON : ');
ReadLn(Reg.CentroEst);

until Reg.CentroEst in [1..6];

case Reg.CentroEst of

1 : WriteLn ('Capital');
2 : WriteLn ('Barquisimeto');
3 : WriteLn ('Merida');
4 : WriteLn ('Zulia');
5 : WriteLn ('Nueva Esparta');
6 : WriteLn ('Falcon');
else
WriteLn ('Opcion Invalida');
End;

Case Reg.CentroEst of
1 : begin
if Not(Reg.CentroEst=1) then capital:=capital+1;

if barquisimeto >=1 then barquisimeto:=barquisimeto-1;
if merida >=1 then merida:=merida-1;
if zulia >=1 then zulia:=zulia-1;
if nuevaesparta >=1 then nuevaesparta:=nuevaesparta-1;
if falcon >=1 then falcon:=falcon-1
End;




2 : begin
if Not(Reg.CentroEst=2) then barquisimeto:=barquisimeto+1;

if capital >=1 then capital:=capital-1;
if merida >=1 then merida:=merida-1;
if zulia >=1 then zulia:=zulia-1;
if nuevaesparta >=1 then nuevaesparta:=nuevaesparta-1;
if falcon >=1 then falcon:=falcon-1
End;

3 : begin

if Not(Reg.CentroEst=3) then merida:=merida+1;
if barquisimeto >=1 then barquisimeto:=barquisimeto-1;
if capital >=1 then capital:=capital-1;
if zulia >=1 then zulia:=zulia-1;
if nuevaesparta >=1 then nuevaesparta:=nuevaesparta-1;
if falcon >=1 then falcon:=falcon-1
End;


4 : begin
if Not(Reg.CentroEst=4) then zulia:=zulia+1;
if barquisimeto >=1 then barquisimeto:=barquisimeto-1;
if capital >=1 then capital:=capital-1;
if merida >=1 then merida:=merida-1;
if nuevaesparta >=1 then nuevaesparta:=nuevaesparta-1;
if falcon >=1 then falcon:=falcon-1
End;


5 : begin
if Not(Reg.CentroEst=5) then nuevaesparta:=nuevaesparta+1;
if barquisimeto >=1 then barquisimeto:=barquisimeto-1;
if capital >=1 then capital:=capital-1;
if merida >=1 then merida:=merida-1;
if zulia >=1 then zulia:=zulia-1;
if falcon >=1 then falcon:=falcon-1
End;

6 : begin
if Not(Reg.CentroEst=6) then falcon:=falcon+1;
if barquisimeto >=1 then barquisimeto:=barquisimeto-1;
if capital >=1 then capital:=capital-1;
if merida >=1 then merida:=merida-1;
if nuevaesparta >=1 then nuevaesparta:=nuevaesparta-1;
if zulia >=1 then zulia:=zulia-1
End;

else
End;

Reg.Capi:=capital;
Reg.Bar:=barquisimeto;
Reg.Meri:=merida;
Reg.Zuli:=zulia;
Reg.NvaE:=nuevaesparta;
Reg.Falc:=falcon;
End;
End;




Until (Op = '0') Or (Op = '9');

If Op ='0'
then Exit;

If Op='9'
Then seek(Arch, contador)
Write(Arch, Reg);

GotoXY (27, 14);
Write ('Edicion del Registro Finalizado');
PulsarUnaTecla;
End;

Close(Arch);
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