Ayuda con un programa de tablas y registros
Publicado por Josito (2 intervenciones) el 14/03/2015 15:58:19
Hola a todos, necesito que alguien me diga porque me da error al especificar los parámetros de buscar_producto en los procedimientos de eliminar_producto y modificar producto (Os lo señalo en el programa con flechas) . Os adjunto al programa, gracias por ayudarme.
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
Program UNIDAD8;
Const
Tammaxcesta=3;
Type
Tproducto=record
nombre:string;
num_unidades:integer;
precio_unidad:real;
en_cesta:boolean;
end;
Tcesta = array [0..Tammaxcesta] of Tproducto;
Var
unacesta:Tcesta; (* variable del tipo cesta*)
total:integer;
Procedure lee_producto (VAR producto:Tproducto);
Begin
producto.en_cesta:=true;
writeln('Escriba los datos del producto: ');
write('Nombre: ');
readln(producto.nombre);
write('Numero de unidades: ');
readln(producto.num_unidades);
write('Precio: ');
readln(producto.precio_unidad);
End;
Procedure inicializa_cesta;
var
i:integer;
Begin
for i:= 1 to TAMMAXCESTA do
begin
unacesta [i]. nombre := '';
unacesta [i]. num_unidades:= 0;
unacesta [i]. precio_unidad:= 0.0;
unacesta [i]. en_cesta := false;
end;
end;
Procedure mostrar_producto (var productocesta:Tproducto);
Begin
writeln;
writeln('El producto de la cesta es: ');
writeln;
writeln('Nombre: ',productocesta.nombre);
writeln('Unidades: ',productocesta.num_unidades);
writeln('Precio por unidad: ',productocesta.precio_unidad:0:2);
writeln('Precio total: ',(productocesta.num_unidades*productocesta.precio_unidad):0:2);
writeln;
End;
Procedure llenar_cesta (VAR unacesta:Tcesta);
Var
i:integer;
Begin
For i:= 1 to Tammaxcesta do
begin
lee_producto(unacesta[i]);
end;
End;
Procedure Mostrar_cesta (unacesta:Tcesta);
var
i:integer;
begin
For i:= 1 to Tammaxcesta do
mostrar_producto(unacesta[i]);
end;
Procedure busca_libre (unacesta:Tcesta; VAR pos_libre:integer);
Var
i:integer;
encontrado:boolean;
Begin
encontrado:=false;
pos_libre:=0;
for i:= 1 to Tammaxcesta do
begin
if (encontrado = false) and (unacesta[i].en_cesta = false) then
begin
pos_libre:=i;
encontrado:= true;
end;
end;
end;
Procedure Incluir_producto_en_cesta (Var unacesta:Tcesta);
Var
i:integer;
begin
i:=0;
busca_libre(unacesta,i);
if (i =0) then
writeln('la cesta esta llena')
else
lee_producto(unacesta[i]);
end;
Procedure cuenta_productos (unacesta:Tcesta; VAR cont:integer);
Var
i:integer;
Begin
cont:=0;
For i:= 1 to Tammaxcesta do
begin
if (unacesta[i].en_cesta = true) then
cont:=cont + 1;
end;
End;
Procedure buscar_producto (UnaCesta:Tcesta; nombre:string; VAR posicion:integer);
Var
i:integer;
begin
for i:= 1 to tammaxcesta do
begin
if (unacesta[i].en_cesta=true) and (nombre=unacesta[i].nombre) then
posicion:=i
end;
end;
Procedure Eliminar_producto (var UnaCesta:TCesta);
var
unproduc : string;
numaux, posicion: integer;
begin
Writeln;
Write ('Nombre del producto a eliminar: ');
numaux:=buscar_producto(unacesta,unproduc); -------->>> Me da error al compilar
If (numaux = 0) then
writeln ('Producto no encontrado')
else
begin
UnaCesta[numaux].en_cesta := false;
Writeln ('Producto numero: ',numaux,'encontrado y eliminado');
end;
End;
Procedure modificar_producto(Var unacesta:Tcesta);
Var
unproducto:string;
numaux:integer;
cambio:integer;
nuevonombre: string;
nuevonumero:integer;
nuevoprecio:real;
begin
Writeln;
Write ('Nombre del producto a modificar: ');
Readln(unproducto);
numaux:= Buscar_producto (unacesta,unproducto); ----------> Me da error al compilar
If numaux = 0 then
writeln ('Producto no encontrado')
else
begin
writeln('Indique el campo a modificar (introduzca un numero)');
writeln('Opciones: 1(nombre), 2(unidades), 3(precio): ');
readln(cambio);
if (cambio = 1) then
begin
writeln('Que nombre quiere poner por: ',unacesta[numaux].nombre);
readln(nuevonombre);
unacesta[numaux].nombre:=nuevonombre;
end
else
if (cambio = 2 ) then
begin
writeln('Que numero de unidades quiere (antes): ',unacesta[numaux].num_unidades);
readln(nuevonumero);
unacesta[numaux].num_unidades:=nuevonumero;
end
else
if (cambio = 3 ) then
begin
writeln('Que precio nuevo quiere (antes): ',unacesta[numaux].precio_unidad:0:2);
readln(nuevoprecio);
unacesta[numaux].precio_unidad:=nuevoprecio;
end
end;
end;
PROCEDURE MENU;
VAR
OPCION: INTEGER;
BEGIN
REPEAT
WRITELN;
WRITELN(' *** MENU PRINCIPAL ***');
WRITELN;
WRITELN('OPCIONES');
WRITELN('1. ANADIR PRODUCTO A LA CESTA');
WRITELN('2. ELIMINAR PRODUCTO DE LA CESTA');
WRITELN('3. MOSTRAR CESTA');
WRITELN('4. MODIFICAR PRODUCTO DE LA CESTA');
WRITELN('5. CONTAR PRODUCTOS DE LA CESTA');
WRITELN('6. SALIR DEL PROGRAMA');
WRITELN;
WRITE('ELIJA UNA OPCION: ');
READLN(OPCION);
IF (OPCION = 1) THEN
BEGIN
Incluir_producto_en_cesta(unacesta);
END
ELSE
IF (OPCION = 2) THEN
ELIMINAR_PRODUCTO(UNACESTA)
ELSE
IF (OPCION = 3) THEN
MOSTRAR_CESTA (UNACESTA)
ELSE
IF (OPCION = 4) THEN
MODIFICAR_PRODUCTO (UNACESTA)
ELSE
IF (OPCION = 5) THEN
Begin
CUENTA_PRODUCTOS(UNACESTA, total);
writeln('La cesta contiene: ',total, 'productos');
end
ELSE
IF (OPCION = 6) THEN
WRITE('SALIR');
UNTIL (OPCION < 1) OR (OPCION >= 6);
END;
(********** PROGRAMA PRINCIPAL **********)
BEGIN
inicializa_cesta;
writeln('REALICE UNA COMPRA, DEBERA METER',TAMMAXCESTA, 'PRODUCTOS');
writeln;
TOTAL:=0;
MENU;
END.
Valora esta pregunta


0