Ayuda para corregir el programa de inventario
Publicado por Braulio (1 intervención) el 04/05/2016 00:10:54
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
PROGRAM Ej501 (input, output, inventario);
{Gestion de inventario de farmacia}
CONST
MAX_NOMBRE_PROD = 20;
MAX_NOMBRE_LAB = 30;
TYPE
tipoNombreMedicina = PACKED ARRAY[1..MAX_NOMBRE_PROD] OF char;
tipoNombreLab = PACKED ARRAY[1..MAX_NOMBRE_LAB] OF char;
tipoFecha = RECORD
dia : 1..31;
mes : 1..12;
anyo: 2000..2999;
END{tipoFecha};
tipoID = integer;
tipoStock = integer;
tipoPrecio = real;
tipoMedicina = RECORD
nombre : tipoNombreMedicina;
lab : tipoNombreLab;
ident : tipoID;
precio : tipoPrecio;
caducidad: tipoFecha;
stock : tipoStock;
END{tipoMedicina};
tipoFicheroFarmacia = FILE OF tipoMedicina;
VAR
medicina : tipoMedicina;
ficheroDatos : tipoFicheroFarmacia;
Num_Medicamentos: integer;{Numero de productos diferentes anyadidos al fichero de datos.}
seleccion : 0..3;
PROCEDURE Menu();
{Muestra menu de opciones del programa
Acepta: Nada.
Devuelve: Muestra las opciones por pantalla.
}
BEGIN
WRITELN('_____________MENU______________');
WRITELN('1 Introducir medicamento.');
WRITELN('2 Mostrar numero de medicamentos introducidos.');
WRITELN('3 Calcular total productos en stock.');
WRITELN('Nota: Solo creacion del fichero (no modificacion)');
WRITELN('0 Salir');
END;
PROCEDURE IntroducirMedicina (VAR medicina: tipoMedicina; VAR ficheroDatos:tipoFicheroFarmacia ; VAR Num_Medicamentos: integer);
{Introduce un registro tipoMedicina en el fichero e incrementa el registro de productos introducidos.
Acepta: medicamento a introducir en el fichero y fichero
Devuelve: Numero de medicamentos introducidos y fichero modificado.
}
VAR
i: 1..MAX_NOMBRE_PROD;
BEGIN
WRITE('Nombre producto? ');
i:= 1;
REPEAT
READ(medicina.nombre[i]);
i:=i+1;
UNTIL(i>=MAX_NOMBRE_PROD) OR (eoln()=TRUE);
READLN;
WRITE('Nombre laboratorio? ');
i:= 1;
REPEAT
READ(medicina.lab[i]);
i:=i+1;
UNTIL(i>=MAX_NOMBRE_LAB) OR (eoln()=TRUE);
READLN;
WRITE('Identificador del producto? ');
READ(medicina.ident);
WRITE('Precio unitario? ');
READ(medicina.precio);
WRITELN('Fecha de caducidad:');
REPEAT
WRITE(' - Dia (1..31)? ');
READLN(medicina.caducidad.dia);
UNTIL (medicina.caducidad.dia >=1) AND (medicina.caducidad.dia <=31);
REPEAT
WRITE(' - Mes (1..12)? ');
READLN(medicina.caducidad.mes);
UNTIL (medicina.caducidad.mes >= 1 ) AND (medicina.caducidad.mes <= 12);
WRITE(' - Anyo? ');
READLN(medicina.caducidad.anyo);
WRITE('Cantidad en stock? ');
READ(medicina.stock);
WRITE(ficheroDatos, medicina);
Num_Medicamentos:= Num_Medicamentos +1;
WRITELN(Num_Medicamentos, ' introducidos.');
END;
FUNCTION CalcularStock(VAR ficheroDatos: tipoFicheroFarmacia ; num_med: integer): integer;
{Lee todos los registros del fichero y calcula el stock total de productos almacenados.
Acepta: Fichero de registros y una variable tipoMedicina.
Devuelve: El registro en la variable tipoMedicina.
}
VAR
med: tipoMedicina;
i: integer;
BEGIN
CalcularStock:=0;
RESET(ficheroDatos);
FOR i:=1 TO num_med DO
BEGIN
READ(ficheroDatos, med);
CalcularStock:=CalcularStock + med.stock;
END;
END;
BEGIN
ASSIGN (ficheroDatos, 'c:\datos_ej501-pascal.data');{Instruccion no standard de PASCAL}
REWRITE(ficheroDatos); {Solo podemos crear el fichero, no modificarlo!!}
{El fichero de datos se destruira si ya existe!!}
Num_medicamentos := 0;
REPEAT
Menu();
READLN(seleccion);
CASE seleccion OF
1: IntroducirMedicina(medicina, ficheroDatos, Num_Medicamentos);
2: WRITELN('Numero total de productos introducidos hasta el momento: ', Num_Medicamentos);
3: BEGIN
WRITELN('________________Stock________________');
WRITELN('Num. Medicamentos disponibles: ', Num_medicamentos);
WRITELN('Stock total: ', CalcularStock(ficheroDatos, Num_medicamentos));
END;
END{CASE};
UNTIL (seleccion=0);
CLOSE(ficheroDatos);
END.
Valora esta pregunta


-1