RE:altas y bajas en pascal
Publicado por
WILDWAR (1 intervención) el 29/05/2007 05:31:08
MIRA ESTE CODIGO SOLO LE FALTA MODIFICACIONES
/****************************************************************************************\
Program PROVEEDORES_BVIRTUAL;
Uses Crt;
Const
esc = #27;
Type
nodos = ^datos;
datos = record
cod : string[3];
nombre : string[30];
lugar : string[20];
sueldo : real;
liga : nodos
end;
Var
p,q,inicio:nodos;
tecla :char;
procedure inserta_nodo(var p : nodos);
begin
if inicio=nil then
inicio:=p
else
q^.liga:=p;
q:=p
end;
procedure elimina_nodo(var p,q:nodos);
begin
if p=inicio then
begin
if inicio^.liga=nil then
inicio:=nil
else
inicio:=inicio^.liga
end
else
q^.liga := p^.liga;
dispose(p)
end;
procedure libera_memoria;
begin
p:=inicio;
while(p<>nil) do
begin
q:=p;
p:=p^.liga;
dispose(q)
end
end;
function busca_clave(var p,q:nodos;clave:string):boolean;
begin
if inicio <> nil then
begin
p:=inicio;
While ((p^.cod<>clave)and (p^.liga<>nil)) do
begin
q:=p;
p:=p^.liga
end;
if p^.cod=clave then
busca_clave:=true
else
busca_clave:=false
end
else
busca_clave:=false
end;
procedure Agregar;
Var
otro:char;
begin
Repeat
ClrScr;
gotoxy(30,5);Write('ÎÍÎÍÎÍÎÍÎÍINFORMACION DE PROVEEDORESÍÎÍÎÍÎÍÎÍÎ');
New(p);
p^.liga:=nil;
gotoxy(25,7);Write('COD...............:');
ReadLn(p^.cod);
gotoxy(25,8);Write('Nombre Proveedor..:');
ReadLn(p^.nombre);
gotoxy(25,9);Write('Ciudad ...........:');
ReadLn(p^.lugar);
Repeat
{$I-} {validación de entrada de datos}
gotoxy(25,10);write('No. Articulos...: ');
ReadLn(p^.sueldo);
{$I+}
until IOResult=0;
inserta_nodo(p);
gotoxy(20,22);write('Agregar nuevo proveedor s/n? ');
otro:=ReadKey
until otro in ['n','N',Esc]
end;
procedure Eliminar;
Var
otro :char;
clave:string[3];
begin
Repeat
ClrScr;
gotoxy(30,5);Write('ÎÍÎÍÎÍÎÍELIMINAR PROVEEDORÍÎÍÎÍÎÍÎ');
gotoxy(25,7);Write('Cod. Proveedor..:');
ReadLn(clave);
if busca_clave(p,q,clave) then
begin
gotoxy(25,8);Write('Nombre Proveedor....: ');
Write(p^.nombre);
gotoxy(25,9);Write('Ciudad..............: ');
Write(p^.lugar);
gotoxy(25,10);write('Numero de articulos: ');
Write(p^.sueldo:6:2);
gotoxy(20,15);Write('Desea eliminarlo s/n? ');
otro:=ReadKey;Write(otro);
if otro in['s','S'] then
elimina_nodo(p,q)
end
else
begin
gotoxy(20,10); Write('Cod. no existe...')
end;
gotoxy(20,22);write('Desea eliminar otro s/n? ');
otro:=ReadKey
until otro in ['n','N',Esc]
end;
procedure consultas;
begin
p:=inicio;
while p<>nil do
begin
ClrScr;
gotoxy(30,5);Write('ÎÍÎÍÎÍÎÍCONSULTAR PROVEEDORESÍÎÍÎÍÎÍÎ');
gotoxy(25,7);Write('Cod...: ');
Write(p^.cod);
gotoxy(25,8);Write('Nombre Proveedor : ');
Write(p^.nombre);
gotoxy(25,9);Write('Ciudad: ');
Write(p^.lugar);
gotoxy(25,10);write('No. Articulos : ');
Write(p^.sueldo:6:2);
gotoxy(20,22);Write('Presione una tecla...');
p:=p^.liga;
ReadKey
end
end;
begin
inicio:=nil;
Repeat
ClrScr;
gotoxy(25,5);Write('CONSULTA DE PROVEEDORES');
gotoxy(20,8);Write('1....AGREGAR PROVEEDOR');
gotoxy(20,9);Write('2....ELIMINAR PROVEEDOR');
gotoxy(20,10);write('3....CONSULTAR PROVEEDOR');
gotoxy(20,11);Write('4....SALIR (Esc)');
gotoxy(20,13);Write('Opción [ ]');
gotoxy(43,13);
tecla:=ReadKey;
case tecla of
'1' :Agregar;
'2' :Eliminar;
'3' :consultas
end
until tecla in ['4',esc];
libera_memoria;
ClrScr
end.
/*****************************************************************************************\