-
Notifications
You must be signed in to change notification settings - Fork 0
/
fod_P2-6-TiendaDeRopa.pas
168 lines (148 loc) · 4.42 KB
/
fod_P2-6-TiendaDeRopa.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
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
{Se cuenta con un archivo maestro con los artículos de una cadena de venta de indumentaria.
De cada artículo se almacena: código del artículo, nombre, descripción,talle, color, stock disponible, stock mínimo y precio del artículo.
Se recibe diariamente un archivo detalle de cada una de las 15 sucursales de la cadena.
Se debe realizar el procedimiento que recibe los 15 detalles y actualiza el stock del archivo maestro.
La información que se recibe en los detalles es: código de artículo y cantidad vendida.
Además, se deberá informar en un archivo de texto: nombre de artículo, descripción, stock disponible y precio de aquellos artículos
que tengan stock disponible por debajo del stock mínimo.
Nota: todos los archivos se encuentran ordenados por código de artículo.
En cada detalle puede venir 0 o N registros de un determinado artículo.
}
program fod6_generarMaestro;
const
corte = -1;
tam = 3;
valorAlto = 9999;
type
registroMaestro = record
nombre: string;
codigo: integer;
desc: string;
talle: string;
color: string;
stockD: integer;
stockM: integer;
precio: real;
end;
registroDetalle = record
codigo: integer;
cantidadVendida: integer;
end;
detalle = file of registroDetalle;
maestro = file of registroMaestro;
vectorDetalles = array[1..tam] of detalle;
vectorRegistros = array[1..tam] of registroDetalle;
//----------------------------------------------------------------------
procedure leer(var d: detalle; var rd:registroDetalle);
begin
if (not eof(d)) then
read(d,rd)
else
rd.codigo := valorAlto;
End;
//----------------------------------------------------------------------
procedure minimo(var v: vectorDetalles; var vr: vectorRegistros; var min: registroDetalle);
var
i, posMin: integer;
begin
min.codigo := valorAlto;
for i:= 1 to tam do begin
if (vr[i].codigo < min.codigo) then begin
posMin:= i;
min:= vr[i];
end;
end;
if(min.codigo <> valorAlto) then
leer(v[posMin], vr[posMin]);
End;
//----------------------------------------------------------------------
{Se debe realizar el procedimiento que recibe los 15 detalles y actualiza el stock del archivo maestro. }
procedure actualizarMaestro(var m: maestro; var vd: vectorDetalles; var vr: vectorRegistros);
var
totalVentas, actual, i: integer;
min: registroDetalle;
rm: registroMaestro;
found: boolean;
begin
assign(m,'tiendaDeRopa.maestro');
reset(m);
minimo(vd,vr,min);
while (min.codigo <> valorAlto) do begin
actual := min.codigo;
totalVentas := 0;
found:= false;
while(min.codigo = actual) do begin
totalVentas := totalVentas + min.cantidadVendida;
minimo(vd,vr,min);
end;
while(not eof(m) and not found) do begin
read(m,rm);
writeln('código del maestro: ', rm.codigo, ' codigo buscado: ', actual);
if (rm.codigo = actual) then
found := true;
end;
rm.codigo := actual;
rm.stockD:= rm.stockD - totalVentas;
writeln('Elcodigo ', rm.codigo, ' vendió ',totalVentas,'. El stock es ',rm.stockD);
seek(m,filepos(m)-1);
write(m,rm);
end;
close(m);
for i:= 1 to tam do
close(vd[i]);
End;
procedure imprimir(var m: maestro);
var
rm: registroMaestro;
begin
assign(m,'tiendaDeRopa.maestro');
reset(m);
while (not eof(m)) do begin
read(m,rm);
writeln('Código: ', rm.codigo,' *Stock Disponible: ', rm.stockD);
end;
close(m);
End;
//----------------------------------------------------------------------
{Además, se deberá informar en un archivo de texto: nombre de artículo, descripción, stock disponible y precio de aquellos artículos
que tengan stock disponible por debajo del stock mínimo.}
procedure exportarATxt(var m: maestro; var t:Text);
var
rm: registroMaestro;
begin
assign(m,'tiendaDeRopa.maestro');
reset(m);
assign(t,'tiendaDeRopa.txt');
rewrite(t);
while (not eof(m)) do begin
read(m,rm);
if(rm.stockM > rm.stockD) then begin
with rm do begin
writeln(t, desc,' ',stockD,' ',precio:0:2);
end;
end;
end;
close(m);
close(t);
End;
//----------------------------------------------------------------------
VAR
m: maestro;
v: vectorDetalles;
vr: vectorRegistros;
i: integer;
nd: string;
t: text;
BEGIN
for i:= 1 to tam do begin
str(i,nd);
assign(v[i], ' TiendaNumero'+nd);
reset(v[i]);
leer(v[i], vr[i]);
end;
imprimir(m);
writeln();
actualizarMaestro(m,v,vr);
imprimir(m);
exportarATxt(m,t);
END.