Created
June 17, 2018 13:10
-
-
Save matipan/81aa0e51eb7c9afbf00e220c43806dcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Program ej2; | |
uses sysutils; | |
const | |
valoralto = 99999; | |
type | |
producto = record | |
codigo : integer; | |
nombre : string[20]; | |
descripcion : string[30]; | |
stock : integer; | |
end; | |
proddet = record | |
codigo : integer; | |
vendidos : integer; | |
end; | |
detalle = file of proddet; | |
maestro = file of producto; | |
detalles = array [0..29] of detalle; | |
dreg = array [0..29] of proddet; | |
procedure leerD(var d : detalle; var p : proddet); | |
begin | |
if not eof(d) then | |
read(d, p) | |
else | |
p.codigo := valoralto; | |
end; | |
procedure leerM(var m : maestro; var p : producto); | |
begin | |
if not eof(m) then | |
read(m, p) | |
else | |
p.codigo := valoralto; | |
end; | |
procedure sumarStock(var p : producto; var dets : detalles; var prods : dreg); | |
var | |
i : integer; | |
begin | |
for i := 0 to 29 do begin | |
while((prods[i].codigo = p.codigo) and (dreg[i].codigo <> valoralto)) do begin | |
p.stock := p.stock - prods[i].vendidos; | |
leerD(dets[i], prods[i]); | |
end; | |
end; | |
end; | |
procedure actualizar(var m : maestro; var dets : detalles; var ns : text); | |
var | |
regs : dreg; | |
p : producto; | |
i, stockPrevio : integer; | |
begin | |
{Carga inicial de los detalles} | |
for i := 0 to 29 do | |
leerD(dets[i], regs[i]); | |
leerM(m, p); | |
while(p.codigo <> valoralto) do begin | |
stockPrevio := p.stock; | |
sumarStock(p, dets, regs); | |
if stockPrevio = p.stock then | |
writeln('No se vendio el producto ', p.nombre) | |
else begin | |
writeln(ns, p.codigo, ' ', p.nombre); | |
writeln(ns, p.stock, ' ', p.descripcion); | |
end; | |
{Actualizar el archivo maestro} | |
seek(m, filepos(m)-1); | |
write(m, p); | |
leerM(m, p); | |
end; | |
end; | |
var | |
m : maestro; | |
dets : detalles; | |
i : integer; | |
nostock : text; | |
begin | |
assign(nostock, 'sinstock.txt'); | |
rewrite(nostock); | |
assign(m, 'maestro.dat'); | |
reset(m); | |
for i := 0 to 29 do begin | |
assign(dets[i], 'det'+IntToStr(i)+'.dat'); | |
reset(dets[i]); | |
end; | |
actualizar(m, dets, nostock); | |
close(m); | |
close(nostock); | |
for i := 0 to 29 do | |
close(dets[i]); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment