-
Notifications
You must be signed in to change notification settings - Fork 0
/
fod_P2-14-Vuelos.pas
134 lines (113 loc) · 2.79 KB
/
fod_P2-14-Vuelos.pas
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 untitled;
const
tam = 2;
valorAlto = 9999;
valorAltoString = 'zzzzz';
type
rMaestro = record
destino: string;
fecha: integer;
horaSalida: integer;
asientosDisp: integer;
end;
rDetalle = record
destino: string;
fecha: integer;
horaSalida: integer;
asientosOcup: integer;
end;
detalle = file of rDetalle;
maestro = file of rMaestro;
vector = array[1..tam] of detalle;
vectorR = array[1..tam] of rDetalle;
procedure leerM(var m: maestro; var rm: rMaestro);
begin
if (not eof(m)) then
read(m, rm)
else
rm.destino := valorAltoString;
End;
procedure leerD(var d: detalle; var rd: rDetalle);
begin
if (not eof(d)) then
read(d, rd)
else
rd.destino := valorAltoString;
End;
procedure minimo(var v: vector; var vr: vectorR; var min: rDetalle);
var
i, posmin: integer;
begin
min.destino := valorAltoString;
min.fecha := valorAlto;
min.horaSalida := valorAlto;
for i:= 1 to tam do begin
if (vr[i].destino <= min.destino) and (vr[i].fecha <= min.fecha) and (vr[i].horaSalida <= min.horaSalida) then begin
min := vr[i];
posmin := i;
end;
end;
leerD(v[posmin], vr[posmin]);
End;
procedure actualizarMaestro(var v: vector; var vr: vectorR; var m: maestro);
var
rm: rMaestro;
i, cant, ventas: integer;
min: rDetalle;
begin
reset(m);
writeln('Cantidad a comparar: '); readln(cant);
minimo(v, vr, min);
while(min.destino <> valorAltoString) do begin
leerM(m,rm);
while(rm.destino <> min.destino)and (rm.fecha <> min.fecha) and (rm.horaSalida <> min.horaSalida) do
leerM(m,rm);
ventas := 0;
while(rm.destino = min.destino)and (rm.fecha = min.fecha) and (rm.horaSalida = min.horaSalida) do begin
ventas := ventas + min.asientosOcup;
minimo(v,vr,min);
end;
seek(m, filepos(m)-1);
rm.asientosDisp := rm.asientosDisp - ventas;
write(m,rm);
if (ventas < cant) then
writeln('Vuelo que no alcanzó la cantidad mínima de asientos ocupados. Destino: ',rm.destino, ' fecha: ',rm.fecha, ' hora: ', rm.horaSalida,' ventas: ', ventas);
end;
for i:= 1 to tam do
close(v[i]);
close(m);
End;
procedure imprimir(var m: maestro);
var
rm: rMaestro;
begin
reset(m);
leerM(m,rm);
while(rm.destino <> valorAltoString) do begin
writeln('Destino: ',rm.destino, ' fecha: ',rm.fecha, ' hora: ', rm.horaSalida,' asientos libres: ', rm.asientosDisp);
leerM(m,rm);
end;
close(m);
End;
VAR
v: vector;
vr: vectorR;
m: maestro;
i: integer;
nd: string;
BEGIN
assign(m, 'maestroVuelos');
writeln('====== RM ======');
imprimir(m);
writeln('');
for i:= 1 to tam do begin
str(i, nd);
assign(v[i], 'archVuelos'+nd);
reset(v[i]);
leerD(v[i], vr[i]);
end;
actualizarMaestro(v,vr, m);
writeln('');
writeln('====== RM act ======');
imprimir(m);
END.