uses crt;
type
stringacorta=string[30];
stringalunga=string[50];
dati=string;
pnodi=^nodi;
nodi = record
titolo:stringalunga;
autore:stringacorta;
ediz:real;
cased:stringacorta;
prezzo:real;
pros:pnodi
end;
var testo:nodi;
biblioteca:array[1..100] of nodi;
primo:pnodi;
scelta:char;
finito:boolean;
procedure init;
begin
primo:=nil;
end;
function listavuota:boolean;
begin
listavuota:=primo=nil
end;
procedure creanuovotit(var punt:pnodi;info:stringalunga);
begin
new(punt);
punt^.titolo:=info;
punt^.pros:=nil
end;
procedure creanuovoaut(var punt:pnodi;info:stringacorta);
begin
new(punt);
punt^.autore:=info;
punt^.pros:=nil
end;
procedure creanuovoediz(var punt:pnodi;info:real);
begin
new(punt);
punt^.ediz:=info;
punt^.pros:=nil
end;
procedure creanuovocased(var punt:pnodi;info:stringalunga);
begin
new(punt);
punt^.cased:=info;
punt^.pros:=nil
end;
procedure creanuovoprez(var punt:pnodi;info:real);
begin
new(punt);
punt^.prezzo:=info;
punt^.pros:=nil
end;
procedure inserisci;
var nuovo,temp,precedente:pnodi;
datoinput,datoinput2:stringalunga;
datoinput3,datoinput5:real;
datoinput4:stringacorta;
begin
write('Inserisci il titolo del libro: ');
readln(datoinput2);
creanuovotit(nuovo,datoinput2);
if listavuota then
primo:=nuovo
else
if primo^.titolo>nuovo^.titolo then
begin
temp:=primo;
primo:=nuovo;
primo^.pros:=temp
end
else
begin
temp:=primo;
while (temp<>nil)and(nuovo^.titolo>temp^.titolo) do
begin
precedente:=temp;
temp:=temp^.pros
end;
nuovo^.pros := temp;
precedente^.pros:=nuovo
end;
write('Inserisci l''autore del libro: ');
readln(datoinput);
creanuovoaut(nuovo,datoinput);
if listavuota then
primo:=nuovo
else
if primo^.autore>nuovo^.autore then
begin
temp:=primo;
primo:=nuovo;
primo^.pros:=temp
end
else
begin
temp:=primo;
while (temp<>nil)and(nuovo^.autore>temp^.autore) do
begin
precedente:=temp;
temp:=temp^.pros
end;
nuovo^.pros := temp;
precedente^.pros:=nuovo
end;
write('Inserisci l''edizione del libro: ');
readln(datoinput3);
creanuovoediz(nuovo,datoinput3);
if listavuota then
primo:=nuovo
else
if primo^.ediz>nuovo^.ediz then
begin
temp:=primo;
primo:=nuovo;
primo^.pros:=temp
end
else
begin
temp:=primo;
while (temp<>nil)and(nuovo^.ediz>temp^.ediz) do
begin
precedente:=temp;
temp:=temp^.pros
end;
nuovo^.pros := temp;
precedente^.pros:=nuovo
end;
write('Inserisci la casa editrice del libro: ');
readln(datoinput4);
creanuovocased(nuovo,datoinput4);
if listavuota then
primo:=nuovo
else
if primo^.cased>nuovo^.cased then
begin
temp:=primo;
primo:=nuovo;
primo^.pros:=temp
end
else
begin
temp:=primo;
while (temp<>nil)and(nuovo^.cased>temp^.cased) do
begin
precedente:=temp;
temp:=temp^.pros
end;
nuovo^.pros := temp;
precedente^.pros:=nuovo
end;
write('Inserisci il prezzo del libro: ');
readln(datoinput5);
creanuovoprez(nuovo,datoinput5);
if listavuota then
primo:=nuovo
else
if primo^.prezzo>nuovo^.prezzo then
begin
temp:=primo;
primo:=nuovo;
primo^.pros:=temp
end
else
begin
temp:=primo;
while (temp<>nil)and(nuovo^.prezzo>temp^.prezzo) do
begin
precedente:=temp;
temp:=temp^.pros
end;
nuovo^.pros := temp;
precedente^.pros:=nuovo
end;
end;
procedure elimina;
var temp,precedente:pnodi;
datoinput:stringalunga;
datoinput2,datoinput4:stringacorta;
datoinput3,datoinput5:real;
trovato:boolean;
begin
write('Dato da cancellare');
readln(datoinput);
if listavuota then
writeln('La lista Š vuota')
else
begin
trovato:=false;
precedente:=nil;
temp:=primo;
if primo^.titolo=datoinput then
begin
temp:=temp^.pros;
dispose(temp);
trovato:=true
end
else
while(not trovato)and(temp<>nil)do
if temp^.titolo=datoinput then
begin
trovato:=true;
precedente^.pros:=temp^.pros;
dispose(temp)
end
else
begin
precedente:=temp;
temp:=temp^.pros
end;
if not trovato then
begin
writeln('Il dato richiesto non esiste');
readln
end;
end;
end;
procedure stampa;
var temp:pnodi;
begin
clrscr;
writeln;
writeln('²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²');
writeln;
writeln('-- ELENCO COMPLETO --');
writeln;
temp:=primo;
while temp<>nil do
begin
writeln('TITOLO: ',temp^.titolo);
temp:=temp^.pros;
writeln('AUTORE: ',temp^.autore);
temp:=temp^.pros;
writeln('EDIZIONE: ',temp^.ediz);
temp:=temp^.pros;
writeln('CASA EDITRICE: ',temp^.cased);
temp:=temp^.pros;
writeln('PREZZO: ',temp^.prezzo);
temp:=temp^.pros;
writeln('-------------------------.')
end;
writeln('²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²²');
readln
end;
begin
init;
finito:=false;
repeat
clrscr;
gotoxy(1,50);
textbackground(blue);
textcolor(yellow);write(' Premi 0 ');
textcolor(white);write('per uscire');
gotoxy(1,1);
writeln;
writeln;
writeln;
writeln;
writeln(' ----------BENVENUTO NELL''ARCHIVIO LIBRI----------');
writeln;
writeln(' 1: Inserisci un libro');
writeln(' 2: Cancella un libro');
writeln(' 3: Visualizza la lista completa dei libri');
writeln;
repeat
write('Scelta: ');
readln(scelta)
until(scelta>='0')and(scelta<='3');
case scelta of
'0':finito:=true;
'1':inserisci;
'2':elimina;
'3':stampa;
end;
until finito
end.