Pascal/Turbo Pascal - procedure con case of

 
Vista:

procedure con case of

Publicado por PAULA (7 intervenciones) el 23/05/2019 16:52:08
hola buenas,
Estoy realizando un ejercicio en pascal ya esta entero realizado pero la profesora me dice que tengo que poner el case of con la llamada de los procedimiento en el modulo principal.
Asi lo hago pero cuando selecciono una opcion se me ejecuta el procedimiento y el programa se cierra.
No se que comando me falta. Alguien que me ayude.Gracias.
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
program compras;
const
	tammaxcesta=4;
type
	producto= record
		nombre:string;
		unidades: integer;
		precio: real;
		en_cesta:boolean;
	end;
	cesta= array [0..tammaxcesta] of producto;
var
	compra:producto;
	micesta:cesta;
	pos:integer;
	contar:integer;
	opcion1:integer;
 
procedure lee_producto(var compra:producto);
	begin
		compra.en_cesta:=true;
		write ('Producto comprado:');
		readln(compra.nombre);
		write('unidades:');
		readln(compra.unidades);
		write('precio_unidad:');
		readln(compra.precio);
	end;
 
procedure escribe_producto(compra:producto);
	begin
		writeln('Producto comprado: ' , compra.nombre);
		writeln('Cantidad en unidades:', compra.unidades);
		writeln('Precio/Und.:', compra.precio:0:2);
		writeln('Importe:' , compra.unidades*compra.precio:0:2);
	end;
 
procedure inicializa_cesta(var micesta:cesta);
	var
		i:integer;
	begin
 
		for i:= 0 to tammaxcesta do
		micesta[i].en_cesta:=false;
 
	end;
 
procedure mostrar_producto(var micesta:cesta);
	var
		i:integer;
		begin
 
			for i:= 1 to tammaxcesta do
			lee_producto(micesta[i]);
			writeln();
		end;
 
procedure mostrar_cesta(micesta:cesta);
	var
		i:integer;
	begin
		for i:= 1 to tammaxcesta do
		begin
 
			if micesta[i].en_cesta=true then
				begin
					escribe_producto(micesta[i]);
					writeln();
				end;
		end;
	end;
 
procedure cuenta_productos(micesta:cesta; var contar:integer);
	var
 
		i:integer;
	Begin
		contar:=0;
		for i:= 1 to tammaxcesta do
			begin
				if micesta[i].en_cesta=true then
					begin
					contar:=contar+1;
					writeln('Productos en la cesta',contar);
					writeln();
					end;
			end;
	end;
 
 
procedure busca_libre(micesta:cesta; var pos:integer);
	var
 
		i:integer;
		encontrar:boolean;
	begin
		i:=1;
		encontrar:=false;
		pos:=0;
		while ((encontrar=false) and (i=tammaxcesta)) do
			begin
				if micesta[i].en_cesta= false then
					begin
						pos:=i;
						encontrar:=true;
						writeln('Posicion libre', pos);
					end;
				if encontrar=false then
				begin
				pos:=0;
				writeln(pos);
				end;
 
			end;
	end;
 
 
 
 
 
procedure incluir_producto(VAR micesta:cesta);
	var
		pos:integer;
 
	begin
		busca_libre(micesta,pos);
		if micesta[pos].en_cesta= false then
			begin
			lee_producto(micesta[pos]);
			writeln();
			end
		else
		 writeln('Cesta llena');
		 writeln();
	end;
 
procedure buscar_producto(micesta:cesta;var pos:integer);
	var
		nombre:string;
		i:integer;
		encontrado:boolean;
 
	begin
		writeln('Que producto desea buscar en la cesta');
		readln(nombre);
 
 
		for i:= 1 to tammaxcesta do
			begin
				if nombre=micesta[i].nombre then
					begin
						pos:=i;
						encontrado:= true;
						writeln('el producto esta posicion', pos);
						writeln();
					end;
			end;
				if encontrado=false then
					pos:=0;
					writeln('El producto esta posicion', pos);
					writeln();
 
	end;
 
procedure eliminar_producto(var micesta:cesta);
var
	pos:integer;
begin
	writeln('***Eliminar Producto***');
	buscar_producto(micesta,pos);
	if pos=0then
	begin
		write('no hay producto');
	end
	else
		begin
			micesta[pos].en_cesta:= false;
			writeln('Campo', pos, ' eliminado');
			writeln();
		end;
end;
 
procedure modificar_producto(var micesta:cesta);
var
 
	opcion:char;
	pos:integer;
begin
	writeln('Producto a modificar');
	buscar_producto(micesta,pos);
	if pos =0 then
		writeln('no se encuentra el producto')
	else
		begin
			writeln('Opciones de la cesta');
			writeln;
			writeln('a> Nombre producto');
			writeln('b> Precio unidad');
			writeln('c> Unidades');
			writeln('d> Todos los campos');
			writeln;
			write('Introduzca la opcion');
			readln(opcion);
			case (opcion) of
				'a': begin
					write ('Producto');
					readln(micesta[pos].nombre);
					writeln;
					end;
				'b': begin
					write ('Precio unidad');
					readln(micesta[pos].precio);
					writeln;
					end;
				'c': begin
					write ('Unidades');
					readln(micesta[pos].unidades);
					writeln;
					end;
				'd': begin
					micesta[pos].en_cesta:=false;
					incluir_producto(micesta);
					end
				else
					write('Opcion incorrecta');
			end;
		end;
end;
 
procedure menu_cesta(var opcion1:integer);
 
 
	begin
		REPEAT
 
			writeln('**Menu cesta**');
			writeln;
			writeln('1=Añadir');
			writeln('2=Eliminar');
			writeln('3=Mostrar');
			writeln('4=Modificar');
			writeln('5=Contar');
			writeln('6=salir');
			writeln;
			write('Seleccione opcion');
			readln(opcion1);
		until (opcion1>=1) and (opcion1<=6);
 
	end;
 
	begin
 
		menu_cesta(opcion1);
 
		case (opcion1) of
 
			1:incluir_producto(micesta);
			2: eliminar_producto(micesta);
			3: mostrar_cesta(micesta);
			4: modificar_producto(micesta);
			5: cuenta_productos(micesta,contar);
		end;
 
 
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
sin imagen de perfil
Val: 112
Bronce
Ha mantenido su posición en Pascal/Turbo Pascal (en relación al último mes)
Gráfica de Pascal/Turbo Pascal

procedure con case of

Publicado por juanba (40 intervenciones) el 23/05/2019 18:26:14
Sugiero añadir un repeat..until en el programa principal como sigue:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
begin                                     // Programa principal
    repeat                            // Inicio del bucle
        menu_cesta(opcion1);         // Presentar menu
 
    case (opcion1) of        // Y ejecutar la opción elegida
 
        1:incluir_producto(micesta);
 
        2: eliminar_producto(micesta);
 
        3: mostrar_cesta(micesta);
 
        4: modificar_producto(micesta);
 
        5: cuenta_productos(micesta,contar);
 
    end;
    until opcion1 = 6;             // volver a ejecutar el bucle repeat. o terminar
end.

quitándolo del procedimiento menu_cesta. Alli no hace más que repetir la visualización del menú. Aunque si se deja tampoco hará daño (creo).
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

procedure con case of

Publicado por PAULA (7 intervenciones) el 23/05/2019 23:54:12
Gracias por tu respuesta me ha servido!!!!
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