Created
June 17, 2018 14:43
-
-
Save matipan/c5106c92e06e407e93f1c46b3d3e5858 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 ej8; | |
const | |
valoralto = 9999; | |
type | |
producto = record | |
codigo : integer; | |
nombre : string[20]; | |
precio : real; | |
stock : integer; | |
stockMinimo : integer; | |
end; | |
venta = record | |
codigo : integer; | |
vendidas : integer; | |
end; | |
maestro = file of producto; | |
detalle = file 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 crearMaestro(var m : maestro; var input : text); | |
var | |
p : producto; | |
begin | |
readln(input, p.codigo, p.precio, p.stock, p.stockMinimo, p.nombre); | |
while(not eof(input)) do begin | |
write(m, p); | |
readln(input, p.codigo, p.precio, p.stock, p.stockMinimo, p.nombre); | |
end; | |
end; | |
procedure reporte(var m : maestro; var output : text); | |
var | |
p : producto; | |
begin | |
leerM(m, p); | |
while(p.codigo <> valoralto) do begin | |
writeln(output, p.codigo, p.precio, p.stock, p.stockMinimo, p.nombre); | |
leerM(m, p); | |
end; | |
end; | |
procedure parseDetalle(var d : detalle; var input: text); | |
var | |
v : venta; | |
begin | |
readln(input, v.codigo, v.vendidas); | |
while(not eof(input)) do begin | |
write(d, v); | |
readln(input, v.codigo, v.vendidas); | |
end; | |
end; | |
procedure actualizar(var m : maestro; var d : detalle); | |
var | |
actual, stockPrevio : integer; | |
p : producto; | |
v : venta; | |
begin | |
leerM(m, p); | |
leerD(d, v); | |
while(p.codigo <> valoralto) do begin | |
actual := p.codigo; | |
stockPrevio := p.stock; | |
while(v.codigo = actual) do begin | |
p.stock := p.stock - v.vendidas; | |
leerD(d, v); | |
end; | |
if stockPrevio <> p.stock then begin | |
seek(m, filepos(m)-1); | |
write(m, p); | |
end; | |
leerM(m, p); | |
end; | |
end; | |
procedure debajo(var m : maestro; var input : text); | |
var | |
p : producto; | |
begin | |
leerM(m,p); | |
while(p.codigo <> valoralto) do begin | |
if p.stock < p.stockMinimo then | |
writeln(output, p.codigo, p.precio, p.stock, p.stockMinimo, p.nombre); | |
leerM(m,p); | |
end; | |
end; | |
var | |
m : maestro; | |
d : detalle; | |
outStock, det, mae, rep : text; | |
decision : integer; | |
ok : boolean; | |
begin | |
assign(m, 'maestro.dat'); | |
assign(d, 'detalle.dat'); | |
assign(outStock, 'debajominimo.txt'); | |
assign(det, 'ventas.txt'); | |
assign(mae, 'vivero.txt'); | |
assign(rep, 'reporte.txt'); | |
decision := 9; | |
ok := true; | |
while (ok) do | |
begin | |
writeln(''); | |
writeln('***** 1. Crear archivo maestro a partir de vivero.txt'); | |
writeln('***** 2. Listar maestro en reporte.txt'); | |
writeln('***** 3. Crear detalle a partir de ventas.txt'); | |
writeln('***** 4. Actualizar maestro'); | |
writeln('***** 5. Productos de stock bajo en debajominimo.txt'); | |
writeln('***** 0. Salir'); | |
write('Que accion desea realizar? '); | |
read(decision); | |
writeln(''); | |
case decision of | |
{segun la syntax de pascal no se puede poner mas de | |
una sola operacion por case, pero ni ganas de poner | |
los rewrite y esas giladas en las funciones asique | |
nos vimo} | |
0: ok := false; | |
1: rewrite(m);reset(mae);crearMaestro(m, mae); | |
2: reset(m); rewrite(rep); reporte(m, rep); | |
3: rewrite(d); reset(det); parseDetalle(d, det); | |
4: reset(m); reset(d); actualizar(m, d); | |
5: reset(m); rewrite(outStock); debajo(m, outStock); | |
otherwise writeln('Selecciona una de la lista.'); | |
end; | |
end; | |
close(m); | |
close(d); | |
close(outStock); | |
close(det); | |
close(mae); | |
close(rep); | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment