Created
July 1, 2018 15:13
-
-
Save matipan/57d829bf96d88541abc7760f179831fa 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 Parcial; | |
uses sysutils; | |
const | |
valoralto = 9999; | |
type | |
producto = record | |
codigo : integer; | |
nombre : string[20]; | |
descripcion : string[40]; | |
precio : real; | |
stockActual : integer; | |
stockMinimo : integer; | |
end; | |
venta = record | |
codigo : integer; | |
cantidad : integer; | |
end; | |
maestro = file of producto; | |
detalle = file of venta; | |
detalles = array [0..9] of detalle; | |
ventas = array [0..9] of venta; | |
procedure leerM(var m : maestro; var p : producto); | |
begin | |
if not eof(m) then | |
read(m, p) | |
else | |
p.codigo := valoralto; | |
end; | |
procedure leerD(var d : detalle; var v : venta); | |
begin | |
if not eof(d) then | |
read(d, v) | |
else | |
v.codigo := valoralto; | |
end; | |
procedure leerT(var t : text; var p : producto); | |
begin | |
if not eof(t) then | |
begin | |
readln(t, p.codigo, p.precio, p.nombre); | |
readln(t, p.stockActual, p.StockMinimo, p.descripcion); | |
end | |
else | |
begin | |
p.codigo := valoralto; | |
end; | |
end; | |
procedure crear(var m : maestro; var input : text); | |
var | |
p : producto; | |
begin | |
leerT(input, p); | |
while(p.codigo <> valoralto) do begin | |
write(m, p); | |
leerT(input, p); | |
end; | |
end; | |
procedure minimo(var vs : ventas; var iMin : integer; var vMin : venta); | |
var | |
i, min : integer; | |
begin | |
min := 9999; | |
for i := 0 to 9 do begin | |
if vs[i].codigo < min then begin | |
iMin := i; | |
vMin := vs[i]; | |
end; | |
end; | |
end; | |
procedure actualizar(var m : maestro; var dets : detalles); | |
var | |
p : producto; | |
vMin : venta; | |
regs : ventas; | |
i, iMin : integer; | |
actual, totalVentas : integer; | |
begin | |
for i := 0 to 9 do | |
leerD(dets[i], regs[i]); | |
minimo(regs, iMin, vMin); | |
while(vMin.codigo <> valoralto) do begin | |
actual := vMin.codigo; | |
totalVentas := 0; | |
while(vMin.codigo = actual) do begin | |
inc(totalVentas, vMin.cantidad); | |
leerD(dets[iMin], regs[iMin]); | |
minimo(regs, iMin, vMin); | |
end; | |
repeat read(m, p) until (p.codigo = actual); | |
dec(p.stockActual, totalVentas); | |
seek(m, filepos(m)-1); | |
write(m,p); | |
end; | |
end; | |
var | |
m : maestro; | |
input : text; | |
dets : detalles; | |
i : integer; | |
begin | |
assign(m, 'maestro.dat'); | |
assign(input, 'productos.txt'); | |
for i := 0 to 9 do begin | |
assign(dets[i], 'detalle'+IntToStr(i)+'.dat'); | |
reset(dets[i]); | |
end; | |
rewrite(m); | |
reset(input); | |
crear(m, input); | |
close(m); | |
close(input); | |
reset(m); | |
actualizar(m, dets); | |
close(m); | |
for i := 0 to 9 do | |
close(dets[i]); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment