Pascal/Turbo Pascal - simplificar un codigo urgente

 
Vista:

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 07/02/2013 00:39:54
Buenas, este pseudocodigo lo tengo que separar en funciones y procedimientos, nada de anidados, todos los tengo que juntar en el programa principal, aparte tengo quitarle procedimientos inecesarios algunos FOR, porque luego todas las constantes las trabajare como variables en archivos y registros... me gustaria me ayudaran a ordenar todo primero por favor. Espero lo entiendan.

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
program proyecto;
uses crt;
Const
	Semilla=0;
	MULTI=13;
	INCRE=65;
	MODULO=100;
	Dem_A=36;
	Dem_B=48;
	Dem_C=60;
	Dem_D=72;
	Dem_E=84;
	Dem_F=96;
	dias=3;
	Prec_pan=0.40;
	Costo_pan=0.25;
	Costo_esc=-0.15;
	Prec_salv=0.10;
	N_Pol=6;
Var
	num_aleat,num_aleat2,Demanda,J,i,k,cont,Z,Produccion,l:integer;
	Y,Ingreso,Escasz,Ingrs_Salv,Costo,G,Promedio,sum_gan,prom:real;
	Tip_dem:string[6];
	Gan_Pol:array [1..N_Pol] of real;
 
 
Function Congruencial_Lineal(Sem:integer):Integer;
var
	aleat:integer;
Begin
	aleat:=(MULTI*Sem+INCRE) Mod Modulo;
	Congruencial_Lineal:=aleat;
End;
 
Procedure Tipo_demanda;
Const
	Alt=29;
	Med=74;
	Baja=99;
begin
	num_aleat:=Congruencial_Lineal(num_aleat);
	If (num_aleat >= 0) and (num_aleat <=Alt) then
		Tip_dem := 'Alta'
	else
		If (num_aleat > Alt) and (num_aleat <= Med) then
				Tip_dem := 'Media'
		else
			If (num_aleat > Med) and (num_aleat <= Baja) then
				Tip_dem := 'Baja';
Writeln('Tipo de demanda=',Tip_dem,' Numero Aleatorio para Tipo=',num_aleat);
end;
 
Function  Demanda1:integer;
			Const
				Alt1=04;
				Alt2=14;
				Alt3=39;
				Alt4=69;
				Alt5=89;
				Alt6=99;
				Med1=09;
				Med2=29;
				Med3=59;
				Med4=84;
				Med5=94;
				Med6=99;
				Baj1=14;
				Baj2=39;
				Baj3=74;
				Baj4=89;
				Baj5=94;
				Baj6=99;
				begin
					If (Tip_dem='Alta') then
						num_aleat2:=Congruencial_Lineal(num_aleat);
						If (num_aleat2 >= 0) and (num_aleat2 <= Alt1) then
							Demanda:=Dem_A
						else
							If (num_aleat2 > Alt1) and (num_aleat2 <= Alt2) then
								Demanda:=Dem_B
							else
								If (num_aleat2 > Alt2) and (num_aleat2 <= Alt3) then
									Demanda:=Dem_C
								else
									If (num_aleat2 > Alt3) and (num_aleat2 <= Alt4) then
										Demanda:=Dem_D
									else
										If (num_aleat2 > Alt4) and (num_aleat2 <= Alt5) then
											Demanda:=Dem_E
										else
												Demanda:=Dem_F;
 
					If (Tip_dem='Media') then
						num_aleat2:=Congruencial_Lineal(num_aleat);
						If (num_aleat2 >= 0) and (num_aleat2 <= Med1) then
							Demanda:=Dem_A
						else
							If (num_aleat2 > Med1) and (num_aleat2 <= Med2) then
								Demanda:=Dem_B
							else
								If (num_aleat2 > Med2) and (num_aleat2 <= Med3) then
									Demanda:=Dem_C
								else
									If (num_aleat2 > Med3) and (num_aleat2 <= Med4) then
										Demanda:=Dem_D
									else
										If (num_aleat2 > Med4) and (num_aleat2 <= Med5) then
											Demanda:=Dem_E
										else
												Demanda:=Dem_F;
					If (Tip_dem='Baja') then
						num_aleat2:=Congruencial_Lineal(num_aleat);
						If (num_aleat2 >= 0) and (num_aleat2 <= Baj1) then
							Demanda:=Dem_A
						else
							If (num_aleat2 > Baj1) and (num_aleat2 <= Baj2) then
								Demanda:=Dem_B
							else
								If (num_aleat2 > Baj2) and (num_aleat2 <= Baj3) then
									Demanda:=Dem_C
								else
									If (num_aleat2 > Baj3) and (num_aleat2 <= Baj4) then
										Demanda:=Dem_D
									else
										If (num_aleat2 > Baj4) and (num_aleat2 <= Baj5) then
											Demanda:=Dem_E
										else
												Demanda:=Dem_F;
Writeln	('Demanda=',Demanda,' Numero aleat para demanda=',num_aleat2);
Demanda1:=Demanda;
end;
Procedure Ganancia;
Begin
	i:=36;l:=0;
	Repeat
		l:=l+1;
		For k:=1 to dias do begin
			Tipo_demanda;
			Z:=Demanda1;
			If (Z=i) then
			begin
				Escasz:=0.0;
				Ingrs_Salv:=0.0;
				Ingreso:=Z*Prec_pan;
				Costo:=Z*Costo_pan;
				G:=Ingreso-Costo+Ingrs_Salv-Escasz;
			end;
				If (Z>i) then
				begin
					Ingrs_Salv:=0.0;
					Escasz:=(Z-i)*Costo_esc;
					Ingreso:=Z*Prec_pan;
					Costo:=Z*Costo_pan;
					G:=Ingreso-Costo+Prec_Salv*Ingrs_Salv-Escasz;
				end
				else
				begin
					If (Z<i) then
					Begin
						Escasz:=0.0;
						Ingrs_Salv:=(i-Z)*Prec_salv;
						Ingreso:=Z*Prec_pan;
						Costo:=Z*Costo_pan;
						G:=Ingreso-Costo+Ingrs_Salv-Costo_esc*Escasz;
					end
				end;
			Writeln('Ingreso=$',Ingreso:0:2);
			Writeln('Escasez=$',Escasz:0:2);
			Writeln('Ingreso de Salvamento=$',Ingrs_Salv:0:2);
			Writeln ('Ganancia=$',G:0:2);
		end;
		i:=i+12;
	sum_gan:=sum_gan+G;
	Promedio:= sum_gan/dias;
	Gan_Pol[l]:=Promedio;
	Until (i=108);
End;
 
Function Politica_Seleccionada:real;
begin
	prom:=0.0;
	For l:=1 to N_Pol do begin
		If (Gan_Pol[l]>prom) then
			prom:=Gan_Pol[l];
			writeln(Gan_Pol[l]:0:2);
	end;
	Writeln ('Promedio mayor=', prom:0:2);
	Politica_Seleccionada:=prom;
	Readkey;
end;
 
Begin
clrscr;
num_aleat:=Congruencial_Lineal(Semilla);
Ganancia;
Y:=Politica_Seleccionada;
readkey;
 
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

simplificar un codigo urgente

Publicado por tugatime (44 intervenciones) el 07/02/2013 01:28:07
Amigo, seria mas facil ayudarte si dices que tiene que hacer el programa el general, y si explicas un poco que hace casa procedimiento y funcion.
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

simplificar un codigo urgente

Publicado por tugatime (44 intervenciones) el 07/02/2013 01:50:38
Una pregunta, en el procedimiento "Tipo_demanda" y en la funcion "Demanda1" las constantes que has puesto, son para quedar siempre con el mismo valor o su valor puede cambiar ??
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 07/02/2013 02:18:19
Las pusimos como constantes porque dijo, que si queria cambiar sus valores ella los modificaba directamente en constantes, pero siempre se usara el mismo valor alli dado, no se si me explique o entendi mal su pregunta.
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

simplificar un codigo urgente

Publicado por tugatime (44 intervenciones) el 07/02/2013 14:13:18
Yo lo digo, porque si esas constante nunca, NUNCA vas a cambiar su valor, directamente las puedes poner dentro del begin..end en su sitio correspondiente y asi se quedaria mas pequeño el programa. Pero si ves que vas a cambiar su valor, entonces dejalas como estan.
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 07/02/2013 23:29:34
No entiendo, me podria explicar en que Begin y end van por favor.
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

simplificar un codigo urgente

Publicado por tugatime (44 intervenciones) el 08/02/2013 00:48:14
Yo me refiero que en el procedimiento "Tipo_demanda" y en la funcion "Demanda1" tienes muchos tipos. Luego esos tipos los utilizas en el en el begin..end del propio procedimiento y de la funcion. Yo digo que si esas constantes no vas a cambiar su valor nunca, puedes quitar las constantes y poner directamente los numeros en sus respectivos sitios en el begin..end del procedimiento y de la funcion. Asi el programa se queda mas pequeño.
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 08/02/2013 04:36:38
Podria hacer un pequeño ejemplo y luego alli yo podria hacerlo en todo el programa por favor.
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

simplificar un codigo urgente

Publicado por tugatime (44 intervenciones) el 08/02/2013 14:07:26
Mira, asi es como tu tienes tu funcion "Demanda1":

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
Function Demanda1:integer;
         Const
              Alt1=04;
              Alt2=14;
              Alt3=39;
              Alt4=69;
              Alt5=89;
              Alt6=99;
              Med1=09;
              Med2=29;
              Med3=59;
              Med4=84;
              Med5=94;
              Med6=99;
              Baj1=14;
              Baj2=39;
              Baj3=74;
              Baj4=89;
              Baj5=94;
              Baj6=99;
 
         begin
              If (Tip_dem='Alta') then
                 num_aleat2:=Congruencial_Lineal(num_aleat);
 
              If (num_aleat2 >= 0) and (num_aleat2 <= Alt1) then
                 Demanda:=Dem_A
              else
                  If (num_aleat2 > Alt1) and (num_aleat2 <= Alt2) then
                     Demanda:=Dem_B
                  else
                      If (num_aleat2 > Alt2) and (num_aleat2 <= Alt3) then
                         Demanda:=Dem_C
                      else
                          If (num_aleat2 > Alt3) and (num_aleat2 <= Alt4) then
                             Demanda:=Dem_D
                          else
                              If (num_aleat2 > Alt4) and (num_aleat2 <= Alt5) then
                                 Demanda:=Dem_E
                              else
                                  Demanda:=Dem_F;
 
              If (Tip_dem='Media') then
                 num_aleat2:=Congruencial_Lineal(num_aleat);
 
              If (num_aleat2 >= 0) and (num_aleat2 <= Med1) then
                 Demanda:=Dem_A
              else
                  If (num_aleat2 > Med1) and (num_aleat2 <= Med2) then
                     Demanda:=Dem_B
                  else
                      If (num_aleat2 > Med2) and (num_aleat2 <= Med3) then
                         Demanda:=Dem_C
                      else
                          If (num_aleat2 > Med3) and (num_aleat2 <= Med4) then
                             Demanda:=Dem_D
                          else
                              If (num_aleat2 > Med4) and (num_aleat2 <= Med5) then
                                 Demanda:=Dem_E
                              else
                                  Demanda:=Dem_F;
 
              If (Tip_dem='Baja') then
                 num_aleat2:=Congruencial_Lineal(num_aleat);
 
              If (num_aleat2 >= 0) and (num_aleat2 <= Baj1) then
                 Demanda:=Dem_A
              else
                  If (num_aleat2 > Baj1) and (num_aleat2 <= Baj2) then
                     Demanda:=Dem_B
                  else
                      If (num_aleat2 > Baj2) and (num_aleat2 <= Baj3) then
                         Demanda:=Dem_C
                      else
                          If (num_aleat2 > Baj3) and (num_aleat2 <= Baj4) then
                             Demanda:=Dem_D
                          else
                              If (num_aleat2 > Baj4) and (num_aleat2 <= Baj5) then
                                 Demanda:=Dem_E
                              else
                                  Demanda:=Dem_F;
 
               Writeln	('Demanda=',Demanda,' Numero aleat para demanda=',num_aleat2);
               Demanda1:=Demanda;
         end;


Como puedes ver tienes muchas constantes. Estas constantes te hacen el programa mas y mas grande. Pues tu lo que puedes hacer es. Si esas constantes nunca cambian su valor (si no sabes a que valor me refiero, pues me refiero al numero que tienes despues del igual) Lo que puedes hacer es eliminar las constantes y poner directamente el numero en sus respectivos sitios en los if dentro del begin..end. Mira, aqui te dejo como quedaria:

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
Function Demanda1:integer;
         begin
              If (Tip_dem='Alta') then
                 num_aleat2:=Congruencial_Lineal(num_aleat);
 
              If (num_aleat2 >= 0) and (num_aleat2 <= 04) then
                 Demanda:=Dem_A
              else
                  If (num_aleat2 > 04) and (num_aleat2 <= 14) then
                     Demanda:=Dem_B
                  else
                      If (num_aleat2 > 14) and (num_aleat2 <= 39) then
                         Demanda:=Dem_C
                      else
                          If (num_aleat2 > 39) and (num_aleat2 <= 69) then
                             Demanda:=Dem_D
                          else
                              If (num_aleat2 > 69) and (num_aleat2 <= 89) then
                                 Demanda:=Dem_E
                              else
                                  Demanda:=Dem_F;
 
              If (Tip_dem='Media') then
                 num_aleat2:=Congruencial_Lineal(num_aleat);
 
              If (num_aleat2 >= 0) and (num_aleat2 <= 09) then
                 Demanda:=Dem_A
              else
                  If (num_aleat2 > 09) and (num_aleat2 <= 29) then
                     Demanda:=Dem_B
                  else
                      If (num_aleat2 > 29) and (num_aleat2 <= 59) then
                         Demanda:=Dem_C
                      else
                          If (num_aleat2 > 59) and (num_aleat2 <= 84) then
                             Demanda:=Dem_D
                          else
                              If (num_aleat2 > 84) and (num_aleat2 <= 94) then
                                 Demanda:=Dem_E
                              else
                                  Demanda:=Dem_F;
 
              If (Tip_dem='Baja') then
                 num_aleat2:=Congruencial_Lineal(num_aleat);
 
              If (num_aleat2 >= 0) and (num_aleat2 <= 14) then
                 Demanda:=Dem_A
              else
                  If (num_aleat2 > 14) and (num_aleat2 <= 39) then
                     Demanda:=Dem_B
                  else
                      If (num_aleat2 > 39) and (num_aleat2 <= 74) then
                         Demanda:=Dem_C
                      else
                          If (num_aleat2 > 74) and (num_aleat2 <= 89) then
                             Demanda:=Dem_D
                          else
                              If (num_aleat2 > 89) and (num_aleat2 <= 94) then
                                 Demanda:=Dem_E
                              else
                                  Demanda:=Dem_F;
 
               Writeln	('Demanda=',Demanda,' Numero aleat para demanda=',num_aleat2);
               Demanda1:=Demanda;
         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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 13/02/2013 02:19:29
Ah ya entiendo, pero lo que ocurre es que la profesora quiere que trabajemos con constantes para que el programa sirva para mas adelante y en otro caso si el programa necesita variar solo se le cambien las constantes y no tener que cambiar y buscar por todo el programa... Lo que tengo que hacer es separar todos los procedimientos y funciones y luego unirlos todos en el programa principal.
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

simplificar un codigo urgente

Publicado por tugatime (44 intervenciones) el 13/02/2013 02:39:10
Por eso te habia preguntado si las constantes tenian siempre el mismo valor y su valor podia cambiar. Era una forma de dejar el programa mas simples. Pero si las constantes pueden cambiar pues dejalo como esta.
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 07/02/2013 02:16:15
Este es el programa

La panadería de Pierre hornea y vende pan francés, Cada mañana, la panadería satisface
la demanda del dia pan recién horneado. Pierre puede hornear el pan sólo en lotes de
una docena de hogazas cada uno. El costo por hogaza es de 25 centavos, Para simplificar,
se supone que la demanda diaria total de pan también ocurre en múltiplos de 12. En los registros se observa que esta demanda. varia de 36 a 96 hojas por día. Una hogaza se vende
en 40 centavos, y cualquier pan sobrante al final del dia vende a una cocina de caridad
a un precio de salvamento de 1O/hogaza. Si la demanda excede a la oferta, se supone que
hay un costo de ganancia-pérdida de 15~/hogaza (debido a la pérdida de renombre, pérdida de clientes con los competidores, etcétera). En los registros de la panadería se observa
que la demanda diaria se puede clasificar en tres tipos: alta, promedio y baja. Estas demandas ocurren con probabilidades de .30, .45 Y .25, respectivamente. La distribución de la demanda por categorías se da en la tabla 7. A Pierre le gustaría determinar el número óptimo
de hogazas por hornear diario para maximizar la ganancia (ingresos + ingresos de salvamento - costo del pan - costo de las ganancias-pérdidas).
Solución Para resolver este problema por simulación, se requiere evaluar varias políticas diferentes.
Aquí, se define una política como el número de hogazas a hornear diario. Cada política específica se evalúa entonces en un periodo fijo para determinar su margen de ganancia. La
política que da la ganancia más alta se selecciona como la mejor.

o aqui en esta pagina se puede apreciar mejor
http://www.itescam.edu.mx/principal/sylabus/fpdb/recursos/r57036.PDF
Donde dice la Panaderia de Pierre, tenemos tres tablas y todo eso debe ir en el programa, pero la profesora nos dijo que debiamos simplificar y eliminar varios FOR, pero no entendi como si todos son necesarios, aparte de eso separar todas las funciones y procedimientos y en el programa principal es que se unira todo.
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 10/02/2013 17:43:21
{Mira el programa tiene los procedimientos separados puedes ejecutarlos individual mente
cada uno.
Referente a los for que sobran creo que te refieres a los if y no a los for pero la forma de
actuar con ellos seria mejor un case y no tantos if.
Referente a las constantes siento comunicarte que una vez asignadas pascal no te dejara
modificar puesto que no las reconocerá como variables y te dará error .
Para que esos cambios fueran posibles en esas constantes su estructura tendría que ser otra
por ejemplo:

tu tienes
MODULO=100;
lo cual pascal solo lo reconocerá como valor fijo
tendría que ser así
MODULO : integer =100;
ahora si te dejara que el valor 100 pueda ser cambiado por otro valor.
Espero entiendas lo que deseo que veas para futuros programas.
Si deseas que te corrija el programa a como yo lo veo que seria mejor dímelo suerte.
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 13/02/2013 02:21:26
Me gustaria que me ayudaras con los del Case, por favor.
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 14/02/2013 19:30:16
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
{Mira a ver si esto te ayuda}
 
 program proyecto;
  uses
      crt;
   Const
      Semilla : integer =0;
      MULTI : integer = 13;
      INCRE : integer = 65;
      MODULO : integer = 100;
      Dem_A : integer = 36;
      Dem_B : integer = 48;
      Dem_C : integer = 60;
      Dem_D : integer = 72;
      Dem_E : integer = 84;
      Dem_F : integer = 96;
      dias : integer = 3;
      Prec_pan : real = 0.40;
      Costo_pan :  real = 0.25;
      Costo_esc :  real = -0.15;
      Prec_salv : real = 0.10;
      N_Pol = 6;
  Var
   num_aleat, num_aleat2, Demanda, J, i, k, cont, Z, Produccion, l : integer;
   Y, Ingreso, Escasz, Ingrs_Salv, Costo, G, Promedio, sum_gan, prom : real;
   Tip_dem : string[6];
   Gan_Pol : array [1..N_Pol] of real;
 
 
   Function Congruencial_Lineal(Sem:integer):Integer;
   var
    aleat : integer;
    Begin
       aleat := (MULTI * Sem + INCRE) Mod Modulo;
       Congruencial_Lineal := aleat;
    End;
 
  Procedure Tipo_demanda;
  begin
    num_aleat := Congruencial_Lineal(num_aleat);
 case num_aleat of
  0..29 : Tip_dem := 'Alta';
 30..74 : Tip_dem := 'Media';
 75..99 : Tip_dem := 'Baja';
  end;
    writeln;
    Writeln('  Tipo de demanda = ',Tip_dem,
          ' Numero Aleatorio para Tipo = ',num_aleat);
 end;
 
  Function Demanda1 : integer;
   begin
    If (Tip_dem = 'Alta') then
    begin
    num_aleat2 := Congruencial_Lineal(num_aleat);
    case num_aleat2 of
    0..4 : Demanda := Dem_A;
   5..14 : Demanda := Dem_B;
  15..39 : Demanda := Dem_C;
  40..69 : Demanda := Dem_D;
  70..89 : Demanda := Dem_E;
  else
    Demanda:=Dem_F;
   end;
  end;
 
  If (Tip_dem = 'Media') then
  begin
     num_aleat2:=Congruencial_Lineal(num_aleat);
   case num_aleat2 of
    0..9 : Demanda := Dem_A;
  10..29 : Demanda := Dem_B;
  30..59 : Demanda := Dem_C;
  31..84 : Demanda := Dem_D;
  85..94 : Demanda := Dem_E;
  else
    Demanda := Dem_F;
    end;
  end;
 
  If (Tip_dem = 'Baja') then
  begin
     num_aleat2 := Congruencial_Lineal(num_aleat);
  case num_aleat2 of
  0..14 : Demanda := Dem_A;
 15..39 : Demanda := Dem_B;
 40..74 : Demanda := Dem_C;
 75..89 : Demanda := Dem_D;
 90..94 : Demanda := Dem_E;
 else
    Demanda := Dem_F;
   end;
  end;
    writeln;
    Writeln('  Demanda = ',Demanda,' Numero aleat para demanda = ',num_aleat2);
    Demanda1 := Demanda;
  end;
 
   Procedure Ganancia;
   var
      pp, n : integer;
   Begin
      i := 36;
      l := 0;
      pp := 1;
   Repeat
      l := l + 1;
      For k := 1 to dias do
      begin
          Tipo_demanda;
          Z := Demanda1;
          Escasz := 0.0;
          Ingrs_Salv := 0.0;
          Costo := Z * Costo_pan;
          Ingreso := Z * Prec_pan;
          n := z - i;
   case n of
   0 : begin
            G := Ingreso - Costo + Ingrs_Salv - Escasz;
          end;
   1..99 : begin
            Escasz := (Z - i) * Costo_esc;
            G := Ingreso - Costo + Prec_Salv * Ingrs_Salv - Escasz;
          end;
  -0..0 :  begin
             Ingrs_Salv := (i - Z) * Prec_salv;
             G := Ingreso - Costo + Ingrs_Salv - Costo_esc * Escasz;
           end;
       end;
       Writeln('  Ingreso = $ ',Ingreso:0:2);
       Writeln('  Escasez = $ ',Escasz:0:2);
       Writeln('  Ingreso de Salvamento = $',Ingrs_Salv:0:2);
       Writeln('  Ganancia = $ ',G:0:2);
       pp := pp + 1;
       if pp > 6 then
       begin
          writeln;
          writeln('   Pulse Una Tecla');
          readkey;
          pp := 1;
          clrscr;
       end;
   end;
      i := i + 12;
      sum_gan := sum_gan + G;
      Promedio := sum_gan / dias;
      Gan_Pol[l] := Promedio;
    Until (i = 108);
  End;
 
    Function Politica_Seleccionada:real;
    begin
       prom := 0.0;
       For l := 1 to N_Pol do
       begin
          If (Gan_Pol[l] > prom) then
          prom := Gan_Pol[l];
          writeln('   ',Gan_Pol[l]:0:2);
       end;
       Writeln ('   Promedio mayor = ', prom:0:2);
       Politica_Seleccionada := prom;
    end;
 
   procedure menu;
   var
     dem : integer;
     tec : char;
     sal : boolean;
   begin
      sal := false;
     repeat
         clrscr;
         writeln('    ****** Menu Jeneral ******');
         writeln;
         writeln('   1 = Tipo De Demanda');
         writeln('   2 = Datos demanda 1');
         writeln('   3 = Ganancias');
         writeln('   4 = Politica Seleccionada');
         writeln('   5 = Ver Todo');
         writeln('   6 = Salir');
         writeln;
         writeln('   <<<< Elija Opcion >>>>');
         tec := readkey;
     case tec of
   '1' : begin
            clrscr;
            Tipo_demanda;
            writeln;
            writeln('   Pulse [Enter]');
            readln;
         end;
   '2' : begin
            clrscr;
            Tipo_demanda;
            dem := Demanda1;
            writeln;
            writeln('   Pulse [Enter]');
            readln;
         end;
   '3' : begin
             clrscr;
             Ganancia;
             writeln;
             writeln('   Pulse [Enter]');
             readln;
         end;
   '4' : begin
             clrscr;
             Y := Politica_Seleccionada;
             writeln;
             writeln('   Pulse [Enter]');
             readln;
         end;
   '5' : begin
            clrscr;
            Ganancia;
            Y := Politica_Seleccionada;
            writeln;
            writeln('   Pulse [Enter]');
            readln;
         end;
   '6' : sal := true;
     end;
     until sal = true;
   end;
 
  Begin
    clrscr;
    num_aleat := Congruencial_Lineal(Semilla);
    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
0
Comentar

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 17/02/2013 06:24:20
Buenas, se lo hice llegar a mi tutor y no le parecio me dijo que continuara como iba sin embargo muchisimas gracias creo que me ayudara para un futuro porque me di cuenta de cosas alli que no habia visto, pero volviendo al codigo original, como usaria todas esas variables como registros? el manejo de los registros me confunden un poco, por el ejemplo el repeat va a ir aumentando de 12 en 12, debo colocarlo en un registro como hago para ir aumentándolo con el registro?
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 17/02/2013 13:00:37
Aclaro un punto que creo importante los programas no son para presentarlos tal como los paso
sino para que entendáis el funcionamiento de lo que pedís vosotros de veis de acoplarlo a vuestros
conocimientos puesto que como yo no los conozco solo os presento ejemplos de como bajo
mi parecer debería ser lo cual nunca quiere decir que sea como debe bajo el punto de vista de otra
persono esto es ayuda no ejecución.
Referente a los registros no son variables si no registros como veras un registro cubre todas las
variables el si es muy grande se maneja con punteros para poder disponer de memoria suficiente
un registro seria:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
dato : record
            Semilla : integer;
             MULTI  : integer;
            INCRE : integer;
        MODULO : integer;
            Dem_A  : integer;
            Dem_B  : integer;
            Dem_C  : integer;
            Dem_D  : integer;
             Dem_E  : integer;
             Dem_F  : integer;
                   dias  : integer;
          Prec_pan : real;
        Costo_pan : real;
        Costo_esc : real;
           Prec_salv : real;
                N_Pol : integer
          end;
 
 var
     dt : dato;
      f : file of  dato;


como puedes apreciar los registros para guardar esas constantes seria de esa forma o bien
de esta otra:
1
2
3
4
5
6
7
8
9
10
const
               n =  12;
              m =  4;
      dato = record
                valor1: array[1..n] of integer;
                 valo2 : array[1..m] of real;
            end;
       var
     dt : dato;
      f : file of  dato;


A la hora de llamarlos seria:
para el primero :
dt.Semilla := 0;
y asi el resto serian asignados los valores de cada uno;
para el segundo :
dt.valo1[1] := 0;
y asi el resto de los integer y para los reales
dt.valo2[1] := 0.40;

una vez cargados los valores se puede guardar para poder modificar después seria.
1
2
3
4
5
assign(f,el nombre y extension);
   rewrite(f);
    seek(f,0);
     write(f,dt);
    close(f);

el archivo quedaría creado con el nombre y extensión que le dieras para poder manejar lo
después.


Aparte de esto hay otras mil formas de manejar los datos cada uno emplea la que bajo su
criterio cree mas conveniente.
Espero esto sea lo que querías saber.
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 17/02/2013 21:42:14
Ah ya entiendo, pues nada sin duda todo lo que me has ayudado me ha servido sin duda alguna gracias... me pondre a trabajar con los registros, cualquier cosa te lo hago comunicar, disculpe hay alguna manera de comunicarme mas directamente con usted?
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 18/02/2013 03:57:45
Ramon, necesito tu ayuda, en este procedimiento Procedure Ganancia;
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
Begin
	i:=36;l:=0;
	Repeat
		l:=l+1;
		For k:=1 to dias do begin
			Tipo_demanda;
			Z:=Demanda1;
			Ingreso:=Z*Prec_pan;
			Costo:=Z*Costo_pan;
				If (Z>i) then
				begin
					Ingrs_Salv:=0.0;
					Escasz:=(Z-i)*Costo_esc;
					G:=Ingreso-Costo+Prec_Salv*Ingrs_Salv-Escasz;
				end
				else
					If (Z<i) then
					begin
						Escasz:=0.0;
						Ingrs_Salv:=(i-Z)*Prec_salv;
						G:=Ingreso-Costo+Ingrs_Salv-Costo_esc*Escasz;
					end
					else
						begin
							Escasz:=0.0;
							Ingrs_Salv:=0.0;
							G:=Ingreso-Costo+Ingrs_Salv-Escasz;
						end;
				Writeln('Ingreso=$',Ingreso:0:2);
				Writeln('Escasez=$',Escasz:0:2);
				Writeln('Ingreso de Salvamento=$',Ingrs_Salv:0:2);
				Writeln ('Ganancia=$',G:0:2);
				end;
		i:=i+12;
		sum_gan:=sum_gan+G;
		Promedio:= sum_gan/dias;
		Gan_Pol[l]:=Promedio;
	Until (i=108);
End;


esa parte de negrita, es para calcular el promedio de cada uno de las demandas, cada promedio se guarda en un vector de tamaño 6 que son las 6 politicas, eso lo debo sacar de alli y hacer otro procedimiento aparte, es decir, calcular el promedio aparte, pero cuando lo hago aparte, no se llena el vector sino que despues que haga todo el repeat, solo muestra el ultimo valor del vector, no hay seis sino uno... como hago? no se si me explique bien, de todas maners me gustaria una forma de comunicarme mas rapidamente contigo si es posible.
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 18/02/2013 17:10:21
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
{Comprueba este tu código para que veas los datos que cargas.
  Referente a la comunicación solo lo efectuó en esta pregunta lo que quieras y te contestare
 lo antes que pueda pero tu no esperes a ultima hora para preguntar dame tiempo de estudiar tu caso como otros muchos gracias espero te pueda servir}
 
program gananci;
 uses
   crt;
   const
      dias : integer = 3;
      MULTI : integer = 13;
      INCRE : integer = 65;
      MODULO : integer = 100;
      Dem_A : integer = 36;
      Dem_B : integer = 48;
      Dem_C : integer = 60;
      Dem_D : integer = 72;
      Dem_E : integer = 84;
      Dem_F : integer = 96;
      Prec_pan : real = 0.40;
      Costo_pan :  real = 0.25;
      Costo_esc :  real = -0.15;
      Prec_salv : real = 0.10;
 
 
   var
     num_aleat, num_aleat2, Demanda, J, i, k, cont, Z, Produccion, l : integer;
     Gan_Pol : array [1..6] of real;
     Y, Ingreso, Escasz, Ingrs_Salv, Costo, G, Promedio, sum_gan, prom : real;
     Tip_dem : string[6];
 
   Function Congruencial_Lineal(Sem:integer):Integer;
   var
    aleat : integer;
    Begin
       aleat := (MULTI * Sem + INCRE) Mod Modulo;
       Congruencial_Lineal := aleat;
    End;
 
    Function Demanda1 : integer;
    begin
       If (Tip_dem = 'Alta') then
       begin
       num_aleat2 := Congruencial_Lineal(num_aleat);
    case num_aleat2 of
    0..4 : Demanda := Dem_A;
   5..14 : Demanda := Dem_B;
  15..39 : Demanda := Dem_C;
  40..69 : Demanda := Dem_D;
  70..89 : Demanda := Dem_E;
  else
    Demanda:=Dem_F;
    end;
   end;
  end;
 
 
   Procedure Tipo_demanda;
   begin
    num_aleat := Congruencial_Lineal(num_aleat);
   case num_aleat of
     0..29 : Tip_dem := 'Alta';
    30..74 : Tip_dem := 'Media';
    75..99 : Tip_dem := 'Baja';
    end;
     writeln;
     Writeln('  Tipo de demanda = ',Tip_dem,
          ' Numero Aleatorio para Tipo = ',num_aleat);
 end;
 
  Begin
	i := 36;
        l := 0;
	Repeat
	   l := l + 1;
	   For k := 1 to dias do
           begin
	     Tipo_demanda;
	     Z := Demanda1;
	     Ingreso := Z * Prec_pan;
	     Costo := Z * Costo_pan;
	     If (Z > i) then
	     begin
	       Ingrs_Salv := 0.0;
	       Escasz := (Z - i) * Costo_esc;
	       G := Ingreso - Costo + Prec_Salv * Ingrs_Salv - Escasz;
	     end
	 else
	   If (Z < i) then
	   begin
	      Escasz := 0.0;
	      Ingrs_Salv := (i - Z) * Prec_salv;
	      G := Ingreso - Costo + Ingrs_Salv - Costo_esc * Escasz;
	   end
       else
          begin
	    Escasz := 0.0;
            Ingrs_Salv := 0.0;
	    G := Ingreso - Costo + Ingrs_Salv - Escasz;
	  end;
	  Writeln('Ingreso=$',Ingreso:0:2);
	  Writeln('Escasez=$',Escasz:0:2);
	  Writeln('Ingreso de Salvamento=$',Ingrs_Salv:0:2);
	  Writeln ('Ganancia=$',G:0:2);
       end;
         i := i + 12;
	 sum_gan := sum_gan + G;
	 Promedio := sum_gan / dias;
	 Gan_Pol[l] := Promedio;
    Until (i = 108);
    clrscr;
    for i := 1 to 6 do
    writeln(gan_pol[i]:8:2);
    readln;
 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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 19/02/2013 01:49:23
Ramon, ya he puesto a funcionar ya casi todo y todo va de maravilla, muchas gracias... Ahora como yo trabajaria con Archivos?, estas contantes
Dem_A : integer = 36;
Dem_B : integer = 48;
Dem_C : integer = 60;
Dem_D : integer = 72;
Dem_E : integer = 84;
Dem_F : integer = 96;
Prec_pan : real = 0.40;
Costo_pan : real = 0.25;
Costo_esc : real = -0.15;
Prec_salv : real = 0.10;
deben estar en archivos ordenados asi...
Lote 12
Costo de pan 40
Variacion de la demanda 36
Precio de venta del pan 40
precio de salvamente 10...
y asi sucesivamente, y cuando lo leamos con Read(Datos, Lote); Read(Datos, Costo_Pan); y asi, como podria llenar ese archivo y luego usarlo, espero tu ayuda muchas gracias.
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 19/02/2013 04:37:48
Ve ramon, disculpa tanta molestia, este es el codigo que quedo...

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
program proyecto;
uses crt;
Const
	Semilla=0;
	MULTI=13;
	INCRE=65;
	MODULO=100;
	Dem_A=36;
	Dem_B=48;
	Dem_C=60;
	Dem_D=72;
	Dem_E=84;
	Dem_F=96;
	Prec_pan=0.40;
	Costo_pan=0.25;
	Costo_esc=0.15;
	Prec_salv=-0.15;
	N_Pol=6;
	dias=10;
Var
	num_aleat,num_aleat2,Demanda,i,k,Z,l,aleat:integer;
	Ingreso,Escasz,Ingrs_Salv,Costo,G,Promedio,sum_gan,prom:real;
	Tip_dem:string[6];
	Gan_Pol:array [1..N_Pol] of real;
 
Function Congruencial_Lineal(Sem:integer):Integer;
var
	aleat:integer;
Begin
	aleat:=(MULTI*Sem+INCRE) Mod Modulo;
	Congruencial_Lineal:=aleat;
End;
 
Procedure Tipo_demanda;
Const
	Alt=29;
	Med=74;
	Baja=99;
begin
	num_aleat:=Congruencial_Lineal(num_aleat);
	If (num_aleat >= 0) and (num_aleat <=Alt) then
		Tip_dem := 'Alta'
	else
		If (num_aleat > Alt) and (num_aleat <= Med) then
			begin
				Tip_dem := 'Media'
			end
		else
			begin
				Tip_dem := 'Baja';
			end;
//Writeln('Tipo de demanda=',Tip_dem,'   Numero Aleatorio para Tipo=',num_aleat);
end;
Function Demanda1:integer;
Const
	Alt1=04;
	Alt2=14;
	Alt3=39;
	Alt4=69;
	Alt5=89;
	Alt6=99;
	Med1=09;
	Med2=29;
	Med3=59;
	Med4=84;
	Med5=94;
	Med6=99;
	Baj1=14;
	Baj2=39;
	Baj3=74;
	Baj4=89;
	Baj5=94;
	Baj6=99;
	begin
	num_aleat2:=Congruencial_Lineal(num_aleat);
		If (Tip_dem='Alta') then
			begin
				If (num_aleat2 >= 0) and (num_aleat2 <= Alt1) then
					Demanda:=Dem_A
				else
					If (num_aleat2 > Alt1) and (num_aleat2 <= Alt2) then
						Demanda:=Dem_B
					else
						If (num_aleat2 > Alt2) and (num_aleat2 <= Alt3) then
							Demanda:=Dem_C
						else
							If (num_aleat2 > Alt3) and (num_aleat2 <= Alt4) then
								Demanda:=Dem_D
							else
								If (num_aleat2 > Alt4) and (num_aleat2 <= Alt5) then
									Demanda:=Dem_E
								else
									Demanda:=Dem_F;
			end
		else
			If (Tip_dem='Media') then
				begin
					If (num_aleat2 >= 0) and (num_aleat2 <= Med1) then
						Demanda:=Dem_A
						else
							If (num_aleat2 > Med1) and (num_aleat2 <= Med2) then
								Demanda:=Dem_B
							else
								If (num_aleat2 > Med2) and (num_aleat2 <= Med3) then
									Demanda:=Dem_C
								else
									If (num_aleat2 > Med3) and (num_aleat2 <= Med4) then
										Demanda:=Dem_D
									else
										If (num_aleat2 > Med4) and (num_aleat2 <= Med5) then
											Demanda:=Dem_E
										else
											Demanda:=Dem_F;
				end
			else
				begin
					If (num_aleat2 >= 0) and (num_aleat2 <= Baj1) then
						Demanda:=Dem_A
					else
						If (num_aleat2 > Baj1) and (num_aleat2 <= Baj2) then
							Demanda:=Dem_B
						else
							If (num_aleat2 > Baj2) and (num_aleat2 <= Baj3) then
								Demanda:=Dem_C
							else
								If (num_aleat2 > Baj3) and (num_aleat2 <= Baj4) then
									Demanda:=Dem_D
								else
									If (num_aleat2 > Baj4) and (num_aleat2 <= Baj5) then
										Demanda:=Dem_E
									else
										Demanda:=Dem_F;
				end;
//Writeln	('Demanda=',Demanda,'    Numero Aleat para demanda=',num_aleat2);	
Demanda1:=Demanda;
end;
Procedure Ganancia;
Begin
	Tipo_demanda;
	Z:=Demanda1;
	Ingreso:=Z*Prec_pan;
	Costo:=Z*Costo_pan;
		If (Z>i) then
		begin
			Ingrs_Salv:=0.0;
			Escasz:=(Z-i)*Costo_esc;
			G:=Ingreso-Costo+Prec_Salv*Ingrs_Salv-Escasz;
		end
		else
			If (Z<i) then
			begin
				Escasz:=0.0;
				Ingrs_Salv:=(i-Z)*Prec_salv;
				G:=Ingreso-Costo+Ingrs_Salv-Costo_esc*Escasz;
			end
			else
				begin
					Escasz:=0.0;
					Ingrs_Salv:=0.0;
					G:=Ingreso-Costo;
				end;
//		Writeln('Ingreso=$',Ingreso:0:2);
//		Writeln('Escasez=$',Escasz:0:2);
//		Writeln('Ingreso de Salvamento=$',Ingrs_Salv:0:2);
//		Writeln ('Ganancia=$',G:0:2);
End;
Procedure Prome;
Begin
	Promedio:= sum_gan/dias;
	Gan_Pol[l]:=Promedio;
end;
Function Politica_Seleccionada:real;
begin
	prom:=0.0;
	For l:=1 to N_Pol do begin
		If (Gan_Pol[l]>prom) then
			prom:=Gan_Pol[l];
			writeln('El promedio de la politica ',l, ' es: ',Gan_Pol[l]:0:2);
	end;
	Writeln ('Promedio mayor=', prom:0:2);
	Politica_Seleccionada:=prom;
	Readkey;
end;
 
Begin
i:=36;l:=0;sum_gan:=0.0;
clrscr;
num_aleat:=Congruencial_Lineal(Semilla);
Repeat
	For k:=1 to dias do begin
		Ganancia;
		sum_gan:=sum_gan+G;
	end;
	l:=l+1;
	Prome;
	i:=i+12;
	sum_gan:=0.0;
Until (i=108);
Writeln(Politica_Seleccionada);
End.


a este codigo, debo hacer los datos de entrada en archivos, los datos de entrada son Tamaño de lote que esto en el codigo es i:=i+12; ese 12, costo por pan que es Costo_pan=0.25; variacion de demanda esto es desde i:=36 hasta el 108, precio de venta del pan Prec_pan : real = 0.40; precio de salvamento Prec_salv : real = 0.10; costo de escasez Costo_esc : real = -0.15;, cantidad de tipos de demanda son 3 por que son (Alta, media y baja). Es esto, no se si lo entiendas
photo hosting sites

los archivos, las lecturas y escribir me tienen demasiado confundida...
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 19/02/2013 21:09: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
{Seria esto}
 
 type
    regdatos = record
          codigo : integer;
       Costo_pan : real;
         demanda : integer;
        Prec_pan : real;
       Prec_salv : real;
       Costo_esc : real;
         demanda : string[5];
      end;
 
 var
    datos : regdatos;
    f : file of regdatos;
 
 procedure carga_o_guarda(nomb : string; q : char); {Q sera (G=Guardar)}
 var                                                {  O (C=Cargar)}
   n : longint;
 begin
    assign(f,nomb);
 {$I-} reset(f); {$I+}
    if ioresult <> 0 then
    begin
       rewrite(f);
       seek(f,0);        {No Existe Lo creamos}
       write(f,datos);
       close(f);
    end
  else
      begin   {si existe Lo A¤adimos}
          if q in['g',G'] then
          begin
              seek(f,filesize(f));
              write(f,datos);
              close(f);
          end;
          if q in['C','c'] then
          begin
              if filesize(f) > 1 then  {Si es mas de uno pedimos cual carga}
              begin
                  writeln;
                  write('Que Registro Desea Cargar Tiene : ',filesize(f) - 1,
                                              ' : ');
                  readln(n);
                  seek(f,n);
                  read(f,datos);
                  close(f);
              end
           else
               begin
                  seek(f,0);  {Si solo tiene  1 lo cargamos}
                  read(f,datos);
                  close(f);
               end;
          end;
      end;
   end;

  {La carga sera al archivo :
    datos.codigo := ;
    datos.Costo_pan := ;
    datos.demanda := ;   [a qui los valores que corresponda en cada caso]
    datos.Prec_pan := ;  [y en el momento adecuado]
    datos.Prec_salv := ;
    datos.Costo_esc := ;
    datos.demanda := ;

  Para recojerlos a las variables:
                               datos.codigo;
                               datos.Costo_pan;
                               datos.demanda;
   [variable de cada caso := ] datos.Prec_pan;
                               datos.Prec_salv;
                               datos.Costo_esc;
                               datos.demanda;
   Espero entiendas esto no se si lo abras dado si tienes dudas meló
   comentas y te pongo un ejemplo}
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 20/02/2013 03:57:11
Ramon, me he guiado por lo que me dijiste, y bueno echando a perder se arreglar, de tantos errores me quedo el codigo asi

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
program proyecto;
uses crt;
Const
	Semilla=0;
	MULTI=13;
	INCRE=65;
	MODULO=100;
	Dem_A=36;
	Dem_B=48;
	Dem_C=60;
	Dem_D=72;
	Dem_E=84;
	Dem_F=96;
	N_Pol=6;
	dias=10;
	decim=0.10;
Var
	prom, Promedio, G, sum_gan:real;
	DATOS_E:text;
	lote, Prec_pan, varia_dem, Costo_pan, Costo_esc, Prec_salv, Alt, Med, Baj,Alt1,Alt2,Alt3,Alt4,Alt5,Alt6,Med1,Med2,Med3,Med4,Med5,Med6,Baj1,Baj2,Baj3,Baj4,Baj5,Baj6:integer;
	num_aleat,num_aleat2,Demanda,i,k,Z,l,aleat:integer;
	Ingreso,Escasz,Ingrs_Salv,Costo:real;
	Tip_dem:string[6];
	Gan_Pol:array [1..N_Pol] of real;
 
Procedure CrearArchEnt;
begin
	clrscr;
	assign(DATOS_E, 'C:\Users\Andrea Guevara\Desktop\Programas Pascal\DATOSENTRADA.txt');
	reset (DATOS_E);
	read(DATOS_E,lote,Costo_pan,varia_dem,Prec_pan,Costo_esc,Prec_salv, Alt, Med, Baj,Alt1,Alt2,Alt3,Alt4,Alt5,Alt6,Med1,Med2,Med3,Med4,Med5,Med6,Baj1,Baj2,Baj3,Baj4,Baj5,Baj6);
	close (DATOS_E);
end;
 
Function Congruencial_Lineal(Sem:integer):Integer;
var
	aleat:integer;
Begin
	aleat:=(MULTI*Sem+INCRE) Mod Modulo;
	Congruencial_Lineal:=aleat;
End;
 
Procedure Tipo_demanda;
	begin
	num_aleat:=Congruencial_Lineal(num_aleat);
	If (num_aleat >= 0) and (num_aleat <=Alt) then
		Tip_dem := 'Alta'
	else
		If (num_aleat > Alt) and (num_aleat <= Med) then
			begin
				Tip_dem := 'Media'
			end
		else
			begin
				Tip_dem := 'Baja';
			end;
Writeln('Tipo de demanda=',Tip_dem,'   Numero Aleatorio para Tipo=',num_aleat);
end;
Function Demanda1:integer;
begin
	num_aleat2:=Congruencial_Lineal(num_aleat);
		If (Tip_dem='Alta') then
			begin
				If (num_aleat2 >= 0) and (num_aleat2 <= Alt1) then
					Demanda:=Dem_A
				else
					If (num_aleat2 > Alt1) and (num_aleat2 <= Alt2) then
						Demanda:=Dem_B
					else
						If (num_aleat2 > Alt2) and (num_aleat2 <= Alt3) then
							Demanda:=Dem_C
						else
							If (num_aleat2 > Alt3) and (num_aleat2 <= Alt4) then
								Demanda:=Dem_D
							else
								If (num_aleat2 > Alt4) and (num_aleat2 <= Alt5) then
									Demanda:=Dem_E
								else
									Demanda:=Dem_F;
			end
		else
			If (Tip_dem='Media') then
				begin
					If (num_aleat2 >= 0) and (num_aleat2 <= Med1) then
						Demanda:=Dem_A
						else
							If (num_aleat2 > Med1) and (num_aleat2 <= Med2) then
								Demanda:=Dem_B
							else
								If (num_aleat2 > Med2) and (num_aleat2 <= Med3) then
									Demanda:=Dem_C
								else
									If (num_aleat2 > Med3) and (num_aleat2 <= Med4) then
										Demanda:=Dem_D
									else
										If (num_aleat2 > Med4) and (num_aleat2 <= Med5) then
											Demanda:=Dem_E
										else
											Demanda:=Dem_F;
				end
			else
				begin
					If (num_aleat2 >= 0) and (num_aleat2 <= Baj1) then
						Demanda:=Dem_A
					else
						If (num_aleat2 > Baj1) and (num_aleat2 <= Baj2) then
							Demanda:=Dem_B
						else
							If (num_aleat2 > Baj2) and (num_aleat2 <= Baj3) then
								Demanda:=Dem_C
							else
								If (num_aleat2 > Baj3) and (num_aleat2 <= Baj4) then
									Demanda:=Dem_D
								else
									If (num_aleat2 > Baj4) and (num_aleat2 <= Baj5) then
										Demanda:=Dem_E
									else
										Demanda:=Dem_F;
				end;
Writeln	('Demanda=',Demanda,'    Numero Aleat para demanda=',num_aleat2);
Demanda1:=Demanda;
end;
Procedure Ganancia;
Begin
	Tipo_demanda;
	Z:=Demanda1;
	Ingreso:=(Z*Prec_pan)*decim;
	Costo:=(Z*Costo_pan)*decim;
		If (Z>varia_dem) then
		begin
			Ingrs_Salv:=0.0;
			Escasz:=((Z-varia_dem)*Costo_esc)*decim;
			G:=(Ingreso-Costo+(Prec_Salv*decim)*Ingrs_Salv-Escasz);
		end
		else
			If (Z<varia_dem) then
			begin
				Escasz:=0.0;
				Ingrs_Salv:=((varia_dem-Z)*Prec_salv)*decim;
				G:=(Ingreso-Costo+Ingrs_Salv-Costo_esc*Escasz)*decim;
			end
			else
				begin
					Escasz:=0.0;
					Ingrs_Salv:=0.0;
					G:=Ingreso-Costo;
				end;
Writeln('Ingreso=$',Ingreso:0:2);
Writeln('Escasez=$',Escasz:0:2);
Writeln('Ingreso de Salvamento=$',Ingrs_Salv:0:2);
Writeln ('Ganancia=$',G:0:2);
End;
Procedure Prome;
Begin
	Promedio:= sum_gan/dias;
	Gan_Pol[l]:=Promedio;
end;
Function Politica_Seleccionada:real;
begin
	prom:=0.0; i:=0;
	For l:=1 to N_Pol do begin
	writeln('El promedio de la politica ',l, ' es: ',Gan_Pol[l]:0:2);
		If (Gan_Pol[l]>prom) then
		begin
			prom:=Gan_Pol[l];
			i:=l;
		end;
	end;
	Writeln ('La Politica Seleccionada es = Politica ',i,' con un margen de ganancia de ', prom:0:2);
	Politica_Seleccionada:=prom;
	Readkey;
end;
 
Begin
clrscr;
CrearArchEnt;
l:=0;sum_gan:=0.0;
num_aleat:=Congruencial_Lineal(Semilla);
Repeat
	For k:=1 to dias do begin
		Ganancia;
		sum_gan:=sum_gan+G;
	end;
	l:=l+1;
	Prome;
	varia_dem:=varia_dem+lote;
	sum_gan:=0.0;
Until (varia_dem=108);
Writeln(Politica_Seleccionada);
End.


Corre el programa en tu computadora si puedes, y eso que sale alli en pantalla todo eso debe ir en un archivo de salida, como hago para meter eso dentro de un archivo? lo que dice Tipo de demanda,Numero Aleatorio para Tipo, Demanda y Numero Aleat para demanda van en un archivo, Ingreso, Escasez, Ingreso de Salvamento y Ganancia en otro archivo, y El promedio de la politica 1,2,3,4,5 y 6 y "La Politica Seleccionada es con un margen de ganancia de" en otro archivo, son tres archivos de salida, yo creo que con un podria medio intentarlo pero con los tres me confunden al llamar los procedimientos y si al llamar el ultimo no se sobreescribiria el primero esa es mi confusion.
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 20/02/2013 13:31:18
{Tu programa no funciona bien no se ejecuta puede tener algún fallo.

Este procedimiento es incorrecto:

1
2
3
4
5
6
7
8
Procedure CrearArchEnt;
begin
	clrscr;
	assign(DATOS_E, 'C:\Users\Andrea Guevara\Desktop\Programas Pascal\DATOSENTRADA.txt');
	reset (DATOS_E);
	read(DATOS_E,lote,Costo_pan,varia_dem,Prec_pan,Costo_esc,Prec_salv, Alt, Med, Baj,Alt1,Alt2,Alt3,Alt4,Alt5,Alt6,Med1,Med2,Med3,Med4,Med5,Med6,Baj1,Baj2,Baj3,Baj4,Baj5,Baj6);
	close (DATOS_E);
end;


por:
para escribir en un archivo es rewrite lo crea y write lo escribe o sea:

1
2
3
4
5
6
7
8
9
10
Procedure CrearArchEnt;
begin
	clrscr;
	assign(DATOS_E, 'C:\Users\Andrea Guevara\Desktop\Programas
                       Pascal\DATOSENTRADA.txt');
         rewrite(DATOS_E); {Esto crea el archivo}
          write(DATOS_E, ,lote,Costo_pan,varia_dem,Prec_pan,Costo_esc,Prec_salv, Alt, Med, Baj,Alt1,Alt2,Alt3,Alt4,Alt5,Alt6,Med1,Med2,Med3,Med4,Med5,Med6,Baj1,Baj2,Baj3,Baj4,Baj5,Baj6);
       {Esto lo guarda}
       close(DATOS_E); {lo cerramos}
   end;


Pero cada vez que ejecutes el programa el archivo sera anulado por el siguiente que entre.
Con lo cual perderás los datos anteriores.

Fíjate la cantidad de variables que tienes eso es mala programación puesto que lo que tu
estas realizando requiere otro tipo de estructuras de datos para un mejor manejo de ellos
ya que cuando salves los datos mira el resultado con un editor de testo como el block de
notas y veras que as cargado en tu archivo.
Coméntame.
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

simplificar un codigo urgente

Publicado por Andrea Guevara (16 intervenciones) el 20/02/2013 15:40:00
No pero ese archivo que habíamos creado el Datosentrada.txt es para leer lo que tengamos allí, estos si son de salida... para los de salida me estas diciendo que haga eso no? con rewrite lo creo y write escribe dentro de el archivo no?

el archivo Datosentrada.txt es un archivo de block de notas que ya tienen variables, lo que estamos es leyendolas en el programa desde alli.
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 20/02/2013 16:32:34
Entiendo disculpa no lo sabia.
en el programa que pones as pasado a variables las constantes que tenias con lo cual
sean perdido los valores por eso no me funciona puesto que tu cargas los valores desde el archivo.
pero eso no es lo que me comentas
[y eso que sale allí en pantalla todo eso debe ir en un archivo
de salida, como hago para meter eso dentro de un archivo?]
y mi respuesta se refiere a esta pregunta.

A hora dime que es lo que te pasa con tranquilidad para poder contestarte con un poco de coherencia
a tu preguntas sino mal lo tenemos.
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

simplificar un codigo urgente

Publicado por Andrea (16 intervenciones) el 20/02/2013 17:51:07
Todos lo que se muestra en pantalla tambien se debe guardar en un archivo, osea que ademas de mostrarlo en el turbo pascal tambien se guarde en el archivo.
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 20/02/2013 19:21:43
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
{Mira lo tuyo arreglado}
 
program proyecto;
uses crt;
type
   regconst = record
        Semilla : integer; {= 0;}
        MULTI : integer;{:=13;}
        INCRE : integer;{=65;}
        MODULO : integer; {100;}
        Dem_A : integer; {36;}
        Dem_B : integer; {=48;}
        Dem_C : integer; {=60;}
        Dem_D : integer; {=72;}
        Dem_E : integer; {=84;}
        Dem_F : integer; {=96;}
        dias : integer; {=3;}
        Prec_pan : real; {=0.40;}
        Costo_pan : real; {=0.25;}
        Costo_esc : real; {=-0.15;}
        Prec_salv : real; {=0.10;}
        Alt1 : integer; {=4;}
        Alt2 : integer; {=14;}
        Alt3 : integer; {=39;}
        Alt4 : integer; {=69;}
        Alt5 : integer; {=89;}
        Alt6 : integer; {=99;}
        Med1 : integer; {=9;}
        Med2 : integer; {=29;}
        Med3 : integer; {=59;}
        Med4 : integer; {=84;}
        Med5 : integer; {=94;}
        Med6 : integer; {=99;}
        Baj1 : integer; {=14;}
        Baj2 : integer; {=39;}
        Baj3 : integer; {=74;}
        Baj4 : integer; {=89;}
        Baj5 : integer; {=94;}
        Baj6 : integer; {=99;}
     end;
 
   ganancias = record
          ingres : real;
          escz   : real;
          ing_sal : real;
          gana : real;
       end;
 
    politica = record
          gra : array[1..20] of real;
          may : real;
        end;
 
   tipodatos = record
          gananc : array[1..100] of ganancias;
          gn : integer;
          polit : politica;
          pn : integer;
        end;
 
  const
     N_Pol = 6;
     Alt = 29;
     Med = 74;
     Baja = 99;
 
Var
datosd : tipodatos;
f : file of tipodatos;
valores : regconst;
ct : file of regconst;
num_aleat,num_aleat2,Demanda,J,i,k,cont,Z,Produccion,l:integer;
Y,Ingreso,Escasz,Ingrs_Salv,Costo,G,Promedio,sum_gan,prom:real;
Tip_dem:string[6];
Gan_Pol:array [1..N_Pol] of real;
 
 
procedure asignavalor;
begin
  valores.Semilla := 0;
  valores.MULTI := 13;
  valores.INCRE := 65;
  valores.MODULO := 100;
  valores.Dem_A := 36;
  valores.Dem_B := 48;
  valores.Dem_C := 60;
  valores.Dem_D := 72;
  valores.Dem_E := 84;
  valores.Dem_F := 96;
  valores.dias := 3;
  valores.Prec_pan := 0.40;
  valores.Costo_pan := 0.25;
  valores.Costo_esc := -0.15;
  valores.Prec_salv := 0.10;
  valores.Alt1 := 4;
  valores.Alt2 := 14;
  valores.Alt3 := 39;
  valores.Alt4 := 69;
  valores.Alt5 := 89;
  valores.Alt6 := 99;
  valores.Med1 := 9;
  valores.Med2 := 29;
  valores.Med3 := 59;
  valores.Med4 := 84;
  valores.Med5 := 94;
  valores.Med6 := 99;
  valores.Baj1 := 14;
  valores.Baj2 := 39;
  valores.Baj3 := 74;
  valores.Baj4 := 89;
  valores.Baj5 := 94;
  valores.Baj6 := 99;
end;
 
procedure creaarchivoconst;
var
  tt : char;
begin
    asignavalor;
    assign(ct,'consta.dat');
  {$I-} reset(ct); {$I+}
  if ioresult <> 0 then
  begin
     rewrite(ct);
     seek(ct,0);
     write(ct,valores);
     close(ct);
  end
 else
    begin
       writeln('El Archivo Existe Desea Cambiarlo [S/N]');
       repeat
          tt := readkey;
       until tt in['s','S','n','N'];
       if tt in['s','S'] then
       begin
          rewrite(ct);
          seek(ct,0);
          write(ct,valores);
          close(ct);
       end;
    end;
 end;
 
 procedure cargavalores;
 begin
     assign(ct,'consta.dat');
  {$I-} reset(ct); {$I+}
  if ioresult <> 0 then
  begin
     writeln('Error El Archivo No Encontrado Pulse [Enter]');
     readln;
     halt(1);
   end
 else
     seek(ct,0);
     read(ct,valores);
     close(ct);
 end;
 
 procedure guardadatos;
 begin
   assign(f,'consta.rst');
   rewrite(f);
   seek(f,0);
   write(f,datosd);
   close(f);
 end;
 
 procedure cargadatos;
 var
    n, t : integer;
 begin
    assign(f,'consta.rst');
  {$I-} reset(f); {$I+}
  if ioresult <> 0 then
  begin
      writeln('El Archivo Solicitado No Se Encontro Pulse [Enter]');
      readln;
      halt(1);
  end
 else
     begin
        seek(f,0);
        read(f,datosd);
        close(f);
        with datosd do
        begin
        for n := 1 to gn do
        begin
        writeln('ingreso   = ',gananc[n].ingres:8:2);
        writeln('escasez   = ',gananc[n].escz:8:2);
        writeln('ingreso s = ',gananc[n].ing_sal:8:2);
        writeln('ganancia  = ',gananc[n].gana:8:2);
        writeln('.................................');
        end;
        for t := 1 to pn do
        begin
           writeln('politica gra = ',polit.gra[t]:8:2);
        end;
           writeln('politica mayor = ',polit.may:8:2);
        end;
        readln;
     end;
 end;
 
Function Congruencial_Lineal(Sem:integer):Integer;
var
aleat:integer;
Begin
aleat:=(valores.MULTI * Sem + valores.INCRE) Mod valores.Modulo;
Congruencial_Lineal:=aleat;
End;
 
Procedure Tipo_demanda;
begin
num_aleat:=Congruencial_Lineal(num_aleat);
If (num_aleat >= 0) and (num_aleat <=Alt) then
Tip_dem := 'Alta'
else
If (num_aleat > Alt) and (num_aleat <= Med) then
Tip_dem := 'Media'
else
If (num_aleat > Med) and (num_aleat <= Baja) then
Tip_dem := 'Baja';
Writeln('Tipo de demanda = ',Tip_dem,' Numero Aleatorio para Tipo = ',
                                                          num_aleat);
end;
 
Function  Demanda1:integer;
begin
If (Tip_dem='Alta') then
num_aleat2:=Congruencial_Lineal(num_aleat);
If (num_aleat2 >= 0) and (num_aleat2 <= valores.Alt1) then
Demanda:=valores.Dem_A
else
If (num_aleat2 > valores.Alt1) and (num_aleat2 <= valores.Alt2) then
Demanda:=valores.Dem_B
else
If (num_aleat2 > valores.Alt2) and (num_aleat2 <= valores.Alt3) then
Demanda:=valores.Dem_C
else
If (num_aleat2 > valores.Alt3) and (num_aleat2 <= valores.Alt4) then
Demanda:=valores.Dem_D
else
If (num_aleat2 > valores.Alt4) and (num_aleat2 <= valores.Alt5) then
Demanda:=valores.Dem_E
else
Demanda:=valores.Dem_F;
 
If (Tip_dem='Media') then
num_aleat2:=Congruencial_Lineal(num_aleat);
If (num_aleat2 >= 0) and (num_aleat2 <= valores.Med1) then
Demanda:=valores.Dem_A
else
If (num_aleat2 > valores.Med1) and (num_aleat2 <= valores.Med2) then
Demanda:=valores.Dem_B
else
If (num_aleat2 > valores.Med2) and (num_aleat2 <= valores.Med3) then
Demanda:=valores.Dem_C
else
If (num_aleat2 > valores.Med3) and (num_aleat2 <= valores.Med4) then
Demanda:=valores.Dem_D
else
If (num_aleat2 > valores.Med4) and (num_aleat2 <= valores.Med5) then
Demanda:=valores.Dem_E
else
Demanda:=valores.Dem_F;
If (Tip_dem='Baja') then
num_aleat2:=Congruencial_Lineal(num_aleat);
If (num_aleat2 >= 0) and (num_aleat2 <= valores.Baj1) then
Demanda:=valores.Dem_A
else
If (num_aleat2 > valores.Baj1) and (num_aleat2 <= valores.Baj2) then
Demanda:=valores.Dem_B
else
If (num_aleat2 > valores.Baj2) and (num_aleat2 <= valores.Baj3) then
Demanda:=valores.Dem_C
else
If (num_aleat2 > valores.Baj3) and (num_aleat2 <= valores.Baj4) then
Demanda:=valores.Dem_D
else
If (num_aleat2 > valores.Baj4) and (num_aleat2 <= valores.Baj5) then
Demanda:=valores.Dem_E
else
Demanda:=valores.Dem_F;
Writeln ('Demanda=',Demanda,' Numero aleat para demanda=',num_aleat2);
Demanda1:=Demanda;
end;
 
Procedure Ganancia;
var
  t, n : integer;
Begin
i:=36;l:=0;
n := 1;
t := 1;
Repeat
l:=l+1;
For k:=1 to valores.dias do
begin
Tipo_demanda;
Z:=Demanda1;
If (Z=i) then
begin
Escasz:=0.0;
Ingrs_Salv:=0.0;
Ingreso:=Z*valores.Prec_pan;
Costo:=Z*valores.Costo_pan;
G:=Ingreso-Costo+Ingrs_Salv-Escasz;
end;
If (Z>i) then
begin
Ingrs_Salv:=0.0;
Escasz:=(Z-i)*valores.Costo_esc;
Ingreso:=Z*valores.Prec_pan;
Costo:=Z*valores.Costo_pan;
G:=Ingreso-Costo+valores.Prec_Salv*Ingrs_Salv-Escasz;
end
else
begin
If (Z<i) then
Begin
Escasz:=0.0;
Ingrs_Salv:=(i-Z)*valores.Prec_salv;
Ingreso:=Z*valores.Prec_pan;
Costo:=Z*valores.Costo_pan;
G:=Ingreso-Costo+Ingrs_Salv-valores.Costo_esc*Escasz;
end
end;
datosd.gananc[n].ingres := Ingreso;
datosd.gananc[n].escz := Escasz;
datosd.gananc[n].ing_sal := Ingrs_Salv;
datosd.gananc[n].gana := G;
n := n + 1;
if n > 100 then
n := 100;
Writeln('Ingreso=$',Ingreso:0:2);
Writeln('Escasez=$',Escasz:0:2);
Writeln('Ingreso de Salvamento=$',Ingrs_Salv:0:2);
Writeln ('Ganancia=$',G:0:2);
end;
i:=i+12;
sum_gan:=sum_gan+G;
Promedio:= sum_gan/valores.dias;
datosd.polit.gra[t] := Promedio;
t := t + 1;
if t > 20 then
t := 20;
Gan_Pol[l]:=Promedio;
Until (i=108);
 datosd.gn := n - 1;
 datosd.pn := t - 1;
End;
 
Function Politica_Seleccionada:real;
begin
prom:=0.0;
For l:=1 to N_Pol do
begin
If (Gan_Pol[l]>prom) then
prom:=Gan_Pol[l];
writeln(Gan_Pol[l]:0:2);
end;
Writeln ('Promedio mayor=', prom:0:2);
Politica_Seleccionada:=prom;
datosd.polit.may := prom;
end;
 
Begin
clrscr;
creaarchivoconst;
cargavalores;
num_aleat:=Congruencial_Lineal(valores.Semilla);
Ganancia;
Y:=Politica_Seleccionada;
guardadatos;
readkey;
clrscr;
cargadatos;
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

simplificar un codigo urgente

Publicado por caterin3 (1 intervención) el 21/12/2014 23:05:25
Hola una pregunta este mismo ejercicio pero en lenguaje c como quedaria?
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

simplificar un codigo urgente

Publicado por ramon (2158 intervenciones) el 21/12/2014 23:30:20
Eso lo tendrás que consultar en la sección del c o implementarlo tu realizando la conversión que por cierto es
bastante parecida que haya suerte.
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