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


0