Tuesday 16 August 2011

Pascal database for organising your music collection.

This is a database to run on Linux which organises your music collection. It can be compiled from a terminal using the free Pascal compiiler. The command to compile is fpc filename. The program can then be run with the command ./filename.

Ref: Pascal made simple by Peter McBride

program records1(input, output);
uses crt, printer;

type
cd = record
artist : string[40];
title : string[40];
style : char;
end;

var
collection : array[1..50] of CD;
diskfile : file of CD;
counter : integer;
choice : integer;

procedure sort;
var
noswaps : boolean;
current : cd;
x : integer;
w :integer;
begin
{repeat
noswaps := true;}
for w := 1 to counter do
for x := 1 to counter -2 do
begin
if collection[x].artist > collection[x + 1].artist then
begin
current := collection[x];
collection[x] := collection[x+1];
collection[x+1] := current;
{noswaps := false;}
end;
end;
{until noswaps;}
end;


procedure save;
var
loop : integer;
begin
assign(diskfile,'cd.dta');
rewrite(diskfile);
for loop := 1 to counter - 1 do
write(diskfile,collection[loop]);
close(diskfile)
end;

procedure load;
begin
assign(diskfile,'cd.dta');
reset(diskfile);
while not eof(diskfile) do
begin
read(diskfile, collection[counter]);
counter := counter + 1;
end;
close(diskfile)
end;

procedure newcd;
begin
with collection[counter] do
begin
write('Enter artist: ');
readln(artist);
write('Enter title: ');
readln(title);
writeln('Enter style (A)mbient, (B)lues, (C)lassical, (F)olk, (I)nstrumental,');
writeln('(J)azz, (M)editation, (N)ew age, (R)ock, (S)oul, (T)hemes: ');
readln(style);
end;
counter := counter + 1;
end;

procedure showone(disk : CD; num : integer);
begin
if disk.artist[1] <> chr(255) then
with disk do
begin
writeln('CD NO. ',num);
writeln(artist);
writeln(title);
writeln(style);
end;
end;

procedure display;
var
loop : integer;
begin
for loop := 1 to counter - 1 do
showone(collection[loop],loop);
end;

procedure search;
var
loop : integer;
target : string[40];
begin
writeln('Enter artist to search for: ');
readln(target);
for loop := 1 to counter do
if collection[loop].artist = target
then showone(collection[loop],loop);
end;

procedure delete;
var
target : integer;
loop : integer;
begin
write('Record number? ');
readln(target);
if(target>0) and (target<counter)
then begin
for loop := target to counter - 1 do
collection[loop] := collection[loop+1];
counter := counter -1;
end;
end;

procedure print;
var
i : integer;
f : text;
begin
for i:= 1 to counter-1 do
begin
writeln(lst,'RECORD NO. ',i);
writeln(lst, collection[i].artist);
writeln(lst, collection[i].title);
writeln(lst, collection[i].style);
writeln(lst,'');
end;
close(lst);
assignlst (f,'|/usr/bin/lpr -m');
rewrite(f);
for i:= 1 to counter-1 do
begin
writeln(f,'RECORD NO. ',i);
writeln(f, collection[i].artist);
writeln(f, collection[i].title);
writeln(f, collection[i].style);
writeln(f,'');
end;
close (f);
end;


begin
counter:= 1;
{load;}
writeln('CD collection organiser');
repeat
{while choice <> '6' do
begin}
writeln('Load file 1');
writeln('New CD 2');
writeln('Display collection 3');
writeln('Select by artist 4');
writeln('Delete record 5');
writeln('Sort records 6');
writeln('Save file 7');
writeln('Print 8');
writeln('Exit 9');
readln(choice);
{case choice of
'1' : load;
'2' : newcd;
'3' : display;
'4' : search;
'5' : delete;
'6' : save;
end;}
if choice = 1 then load;
if choice = 2 then newcd;
if choice = 3 then display;
if choice = 4 then search;
if choice = 5 then delete;
if choice = 6 then sort;
if choice = 7 then save;
if choice = 8 then print;
until choice = 9;
end.

No comments:

Post a Comment