Skip to content

Instantly share code, notes, and snippets.

@matipan
Created June 17, 2018 17:43
Show Gist options
  • Save matipan/3865aa49be4736f09e64a1f94a9eabf5 to your computer and use it in GitHub Desktop.
Save matipan/3865aa49be4736f09e64a1f94a9eabf5 to your computer and use it in GitHub Desktop.
Program ej2;
const
valoralto = 999999;
type
vivienda = record
codigo : integer;
precio : real;
habitaciones : integer;
descripcion : string[20];
end;
maestro = file of vivienda;
procedure leer(var m : maestro; var v : vivienda);
begin
if not eof(m) then
read(m, v)
else
v.codigo := valoralto;
end;
procedure agregar(var m : maestro; v : vivienda);
var
tmp : vivienda;
posA : integer;
begin
{Leer la cabecera de la pila}
leer(m,tmp);
if tmp.codigo = 0 then
{agregamos al final}
posA := filesize(m)
else begin
posA := tmp.codigo;
{actualizamos la cabecera}
seek(m, posA);
read(m, tmp);
seek(m, 0);
write(m, tmp);
end;
seek(m, posA);
write(m, v)
end;
procedure eliminar(var m : maestro; v : vivienda);
var
c,tmp : vivienda;
posA : integer;
begin
leer(m,c);
repeat leer(m, tmp) until ((tmp.descripcion = v.descripcion) or (tmp.codigo = valoralto));
if tmp.descripcion = v.descripcion then begin
tmp.codigo := c.codigo;
c.codigo := filepos(m) - 1;
seek(m, 0);
write(m, c);
seek(m, c.codigo);
write(m, tmp);
end;
end;
var
m : maestro;
begin
assign(m, 'maetro');
rewrite(m);
close(m)
end.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment