Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
записка.doc
Скачиваний:
9
Добавлен:
01.04.2014
Размер:
337.92 Кб
Скачать

7 Анализ полученных результатов

В результате разработки программа имеет достаточно приятный и интуитивно понятный интерфейс. Минусом программы является отсутствие графического интерфейса.

8 Методика работы с программой

songs.dat – файл размещения базы песен. Файл должен размещаться по пути С:\MDB\Songs.dat.

При открытии файла необходимо удостовериться, что он находиться по указанному пути, иначе программа сгенерирует исключение. Если файла не существует, то следует начать работу с добавления записи. После чего можно сохранять запись. Файл будет автоматически создан, а созданные записи будут добавлены в той последовательности, в которой они были добавлены.

Сортировка записей производиться нажатием соответствующих клавиш в латинской кодировке. После нажатия происходит сортировка сравнением ACCI кодов. Для полной корректности сортировка желательно вводить все данные в виде заглавных букв или первая заглавная остальные прописные.

В поиске необходимо указывать точные данные. Программа ищет только полное совпадение с введенным шаблоном.

Навигация по записям происходит путем нажатия стрелок «вверх» и «вниз».

Удаление записи происходит без подтверждения, поэтому необходимо удалять записи только удостоверившись, что курсор находиться именно на той записи, которую вы хотите удалить.

Литература

9 Листинг программы

uses crt;

type

list = ^tSlist;

TSlist = record

group, album, song:string;

year:integer;

next:list;

prev:list;

first:list;

end;

type

TMusicInfo=record

Group1:string[30];

Year1:integer;

Album1:string[20];

Song1:string[30];

end;

label ppp;

var

SpisNach,

SpisEnd,Stk,tmpl,fis:List;

max, min:integer;

gr1,al1,son1:string;

posy,kzap,ye1,i,Nposition,ost:integer;

ch,c1:char;

f:file of TMusicInfo;

st:TMusicInfo;

procedure AddRecord(var nach,ends:List;grAdd,alAdd,sonAdd:string; yeAdd:integer);

begin

if nach=nil then

begin

Getmem(nach,SizeOf(TSList));

nach^.next:=nil;

nach^.prev:=nil;

ends:=nach;

end

else

begin

GetMem(ends^.next,SizeOf(TSlist));

ends^.next^.prev:=ends;

ends:=ends^.next;

ends^.next:=nil;

end;

ends^.next:=nil;

ends^.group:=grAdd;

ends^.year:=yeAdd;

ends^.album:=alAdd;

ends^.song:=sonAdd;

kzap:=kzap+1;

end;

procedure Print(spis1:List;print0:integer);

var sche:integer;

begin

clrscr;

sche:=1;

if spis1=nil then

begin

writeln('No Records');

exit;

end;

posy:=4;

while spis1<>nil do

begin

if (sche>=min) and (sche<=max) then begin

if sche=print0 then begin

textbackground(1);

textcolor(0);

gotoxy(1,posy);

Write('|| ',spis1^.group);

gotoxy(17,posy);

write('|| ', spis1^.album);

gotoxy(40,posy);

write('|| ',spis1^.year);

gotoxy(48,posy);

write('|| ',spis1^.song);

gotoxy(78,posy);

writeln('||');

posy:=posy+1;

spis1:=spis1^.next;

sche:=sche+1;

end

else begin

textbackground(0);

textcolor(15);

gotoxy(1,posy);

Write('|| ',spis1^.group);

gotoxy(17,posy);

write('|| ', spis1^.album);

gotoxy(40,posy);

write('|| ',spis1^.year);

gotoxy(48,posy);

write('|| ',spis1^.song);

gotoxy(78,posy);

writeln('||');

posy:=posy+1;

spis1:=spis1^.next;

sche:=sche+1;

end;

end

else begin

spis1:=spis1^.next;

sche:=sche+1;

end;

end;

end;

procedure search(spis1:List);

var searching:string;

g1,yea1:integer;

sor:Char;

begin

clrscr;

posy:=4;

g1:=0;

if spis1=nil then

begin

writeln('No records');

exit;

end;

writeln('Input whot you wont search');

writeln('1 - Group');

writeln('2 - Album');

writeln('3 - Year');

writeln('4 - Song');

sor:=readkey;

g1:=0;

if sor='1' then begin

Write('Input searching group ');

readln(searching);

clrscr;

gotoxy(1,1);

writeln('===============================================================================');

writeln('II Group II Album II Year II Song II');

writeln('===============================================================================');

while spis1<>nil do

begin

textbackground(0);

textcolor(15);

if spis1^.group = searching then begin

textbackground(0);

textcolor(15);

gotoxy(1,posy);

Write('|| ',spis1^.group);

gotoxy(17,posy);

write('|| ', spis1^.album);

gotoxy(40,posy);

write('|| ',spis1^.year);

gotoxy(48,posy);

write('|| ',spis1^.song);

gotoxy(78,posy);

writeln('||');

posy:=posy+1;

spis1:=spis1^.next;

g1:=1;

end

else spis1:=spis1^.next;

end;

if g1=0 then begin

clrscr;

writeln('No searching records');

end;

readln;

clrscr;

end;

if sor='2' then begin

Write('Input searching album ');

readln(searching);

clrscr;

gotoxy(1,1);

writeln('===============================================================================');

writeln('II Group II Album II Year II Song II');

writeln('===============================================================================');

while spis1<>nil do

begin

if spis1^.album = searching then begin

textbackground(0);

textcolor(15);

gotoxy(1,posy);

Write('|| ',spis1^.group);

gotoxy(17,posy);

write('|| ', spis1^.album);

gotoxy(40,posy);

write('|| ',spis1^.year);

gotoxy(48,posy);

write('|| ',spis1^.song);

gotoxy(78,posy);

writeln('||');

posy:=posy+1;

spis1:=spis1^.next;

g1:=1;

end

else spis1:=spis1^.next;

end;

if g1=0 then begin

clrscr;

writeln('No searching records');

end;

readln;

clrscr;

end;

if sor='3' then begin

Write('Input searching year ');

readln(yea1);

clrscr;

gotoxy(1,1);

writeln('===============================================================================');

writeln('II Group II Album II Year II Song II');

writeln('===============================================================================');

while spis1<>nil do

begin

textbackground(0);

textcolor(15);

if spis1^.year = yea1 then begin

textbackground(0);

textcolor(15);

gotoxy(1,posy);

Write('|| ',spis1^.group);

gotoxy(17,posy);

write('|| ', spis1^.album);

gotoxy(40,posy);

write('|| ',spis1^.year);

gotoxy(48,posy);

write('|| ',spis1^.song);

gotoxy(78,posy);

writeln('||');

posy:=posy+1;

spis1:=spis1^.next;

g1:=1;

end

else spis1:=spis1^.next;

end;

if g1=0 then begin

clrscr;

writeln('No searching records');

end;

readln;

clrscr;

end;

if sor='4' then begin

Write('Input searching song ');

readln(searching);

clrscr;

gotoxy(1,1);

writeln('===============================================================================');

writeln('II Group II Album II Year II Song II');

writeln('===============================================================================');

while spis1<>nil do

begin

textbackground(0);

textcolor(15);

if spis1^.song = searching then begin

textbackground(0);

textcolor(15);

gotoxy(1,posy);

Write('|| ',spis1^.group);

gotoxy(17,posy);

write('|| ', spis1^.album);

gotoxy(40,posy);

write('|| ',spis1^.year);

gotoxy(48,posy);

write('|| ',spis1^.song);

gotoxy(78,posy);

writeln('||');

posy:=posy+1;

spis1:=spis1^.next;

g1:=1;

end

else spis1:=spis1^.next;

end;

if g1=0 then begin

clrscr;

writeln('No searching records');

end;

readln;

clrscr;

end;

end;

Procedure FreeStek(spis1:List);

var

tmp:List;

begin

while spis1<>nil do

begin

tmp:=spis1;

spis1:=spis1^.next;

FreeMem(tmp,SizeOf(TSlist));

end;

end;

procedure OpenFile(var nach, ends:list);

var kol:integer;

begin

kol:=1;

clrscr;

assign(f,'c:\mdb\Songs.dat');

{$I-}

reset(f);

{$I+}

with st do

repeat

read(f,st);

if nach=nil then

begin

Getmem(nach,SizeOf(TSList));

nach^.next:=nil;

nach^.prev:=nil;

ends:=nach;

end

else

begin

GetMem(ends^.next,SizeOf(TSlist));

ends^.next^.prev:=ends;

ends:=ends^.next;

ends^.next:=nil;

end;

ends^.next:=nil;

ends^.group:=group1;

ends^.year:=year1;

ends^.album:=album1;

ends^.song:=song1;

kol:=kol+1;

kzap:=kol;

until eof(f);

close(f);

kzap:=kzap-1;

writeln('read ',kzap,' records');

readln;

end;

procedure SaveRecords(spis1:List);

var y:integer;

begin

y:=0;

assign(f,'c:\mdb\Songs.dat');

{$I-}

reset(f);

{$I+}

if ioresult<>0 then rewrite(f);

if ost=0 then begin

with st do repeat

group1:=spis1^.group;

album1:=spis1^.album;

year1:=spis1^.year;

song1:=spis1^.song;

write(f,st);

spis1:=spis1^.next;

y:=y+1;

if y=kzap then break;

until false;

close(f);

clrscr;

writeln('Record saved');

readln;

end;

if ost>0 then begin

y:=1;

with st do repeat

group1:=spis1^.group;

album1:=spis1^.album;

year1:=spis1^.year;

song1:=spis1^.song;

write(f,st);

spis1:=spis1^.next;

y:=y+1;

if y=kzap then break;

until false;

seek(f,filesize(f)-ost);

truncate(f);

close(f);

clrscr;

writeln('Record saved');

readln;

end;

ost:=0;

END;

procedure SortByGroup(nach:list);

var

tmp,rab:List;

tmps:string;

tmpi:integer;

begin

GetMem(tmp,SizeOf(TSlist));

rab:=nach;

while rab<>nil do

begin

tmp:=rab^.next;

while tmp<>nil do

begin

if tmp^.group<rab^.group then

begin

tmps:=tmp^.group;

tmp^.group:=rab^.group;

rab^.group:=tmps;

tmps:=tmp^.album;

tmp^.album:=rab^.album;

rab^.album:=tmps;

tmpi:=tmp^.year;

tmp^.year:=rab^.year;

rab^.year:=tmpi;

tmps:=tmp^.song;

tmp^.song:=rab^.song;

rab^.song:=tmps;

end;

tmp:=tmp^.next

end;

rab:=rab^.next

end;

end;

procedure SortByAlbum(nach:list);

var

tmp,rab:List;

tmps:string;

tmpi:integer;

begin

GetMem(tmp,SizeOf(TSlist));

rab:=nach;

while rab<>nil do

begin

tmp:=rab^.next;

while tmp<>nil do

begin

if tmp^.album<rab^.album then

begin

tmps:=tmp^.group;

tmp^.group:=rab^.group;

rab^.group:=tmps;

tmps:=tmp^.album;

tmp^.album:=rab^.album;

rab^.album:=tmps;

tmpi:=tmp^.year;

tmp^.year:=rab^.year;

rab^.year:=tmpi;

tmps:=tmp^.song;

tmp^.song:=rab^.song;

rab^.song:=tmps;

end;

tmp:=tmp^.next

end;

rab:=rab^.next

end;

end;

procedure SortByYear(nach:list);

var

tmp,rab:List;

tmps:string;

tmpi:integer;

begin

GetMem(tmp,SizeOf(TSlist));

rab:=nach;

while rab<>nil do

begin

tmp:=rab^.next;

while tmp<>nil do

begin

if tmp^.year<rab^.year then

begin

tmps:=tmp^.group;

tmp^.group:=rab^.group;

rab^.group:=tmps;

tmps:=tmp^.album;

tmp^.album:=rab^.album;

rab^.album:=tmps;

tmpi:=tmp^.year;

tmp^.year:=rab^.year;

rab^.year:=tmpi;

tmps:=tmp^.song;

tmp^.song:=rab^.song;

rab^.song:=tmps;

end;

tmp:=tmp^.next

end;

rab:=rab^.next

end;

end;

procedure SortBySong(nach:list);

var

tmp,rab:List;

tmps:string;

tmpi:integer;

begin

GetMem(tmp,SizeOf(TSlist));

rab:=nach;

while rab<>nil do

begin

tmp:=rab^.next;

while tmp<>nil do

begin

if tmp^.song<rab^.song then

begin

tmps:=tmp^.group;

tmp^.group:=rab^.group;

rab^.group:=tmps;

tmps:=tmp^.album;

tmp^.album:=rab^.album;

rab^.album:=tmps;

tmpi:=tmp^.year;

tmp^.year:=rab^.year;

rab^.year:=tmpi;

tmps:=tmp^.song;

tmp^.song:=rab^.song;

rab^.song:=tmps;

end;

tmp:=tmp^.next

end;

rab:=rab^.next

end;

end;

Procedure DelElem(var spis1,spis2:List;tmp:List);

var

tmpi:List;

begin

if (spis1=nil) or (tmp=nil) then

exit;

if tmp=spis1 then

begin

spis1:=tmp^.next;

if spis1<>nil then

spis1^.prev:=nil

else

spis2:=nil;

FreeMem(tmp,SizeOf(TSList));

end

else

if tmp=spis2 then

begin

spis2:=spis2^.prev;

if spis2<>nil then

spis2^.next:=nil

else

spis1:=nil;

FreeMem(tmp,SizeOf(TSList));

end

else

begin

tmpi:=spis1;

while tmpi^.next<>tmp do

tmpi:=tmpi^.next;

tmpi^.next:=tmp^.next;

if tmp^.next<>nil then

tmp^.next^.prev:=tmpi;

FreeMem(tmp,sizeof(TSList));

end;

end;

Procedure Delrecord(var spis1,spis2:List;posi:integer);

var

int:integer;

tmp:List;

begin

if posi<1 then

exit;

if spis1=nil then

begin

Write('No records');

exit

end;

int:=1;

tmp:=spis1;

while (tmp<>nil) and (int<>posi) do

begin

tmp:=tmp^.next;

inc(int)

end;

if tmp=nil then

begin

Writeln('?«?¬?*?* ? ?®??¤?®??¬ *®¬??®¬ ' ,posi, ' *?? ? ??????.');

writeln('‚ ?????? ????® ' ,int-1, ' ?«?¬?*?®?.');

exit

end;

kzap:=kzap-1;

DelElem(spis1,spis2,tmp);

clrscr;

Writeln('Record deleted');

ost:=ost+1;

end;

begin

max:=16;

min:=1;

SpisNach:=nil;

SpisEnd:=nil;

clrscr;

kzap:=0;

ost:=0;

Nposition:=1;

Stk:=nil;

WRITELN;

WRITELN;

WRITELN;

WRITELN;

WRITELN;

WRITELN;

WRITELN;

WRITELN;

WRITELN(' X X XX XX XXXX XX XX X XXXXX XXXXX ');

WRITELN(' XXX XXX XX XX XX XX XX X XXXXXX XX XX');

WRITELN(' XX X XX XX XX XX XX XXX XX XX XX XX');

WRITELN(' XX XX XX XX XXX XX XXXX XX XX XXXXXXX ');

WRITELN(' XX XX XXX XX XXX XX XX XX XX XX XX XX');

WRITELN(' XX XX XXXXXX X XXX XX XX XX XXXXXX XX XX ');

WRITELN(' XX XX XXXXX XXX XX XX XX XXXXX XXXXXX ');

READKEY;

clrscr;

ppp: while c1<>#27 do begin

{Начало проверки}

if (nposition>max-1) and (max<kzap) then begin

min:=min+1;

max:=max+1;

end;

if (nposition<min+1) and (min>1) then begin

min:=min-1;

max:=max-1;

end;

{Конец проверки}

textbackground(0);

textcolor(15);

gotoxy(1,1);

writeln('===============================================================================');

writeln('II Group II Album II Year II Song II');

writeln('===============================================================================');

gotoxy(1,20);

writeLN('===============================================================================');

WRITELN('F - SEARCH D - DELETE RECORD P - Add Record O - Oen file');

WRITELN('G - Sort by grop; A - Sort by album; Y - Sort by year; S - Sort by song T - Save');

c1:=readkey;

IF c1=#111 THEN BEGIN FreeStek(SpisNach); OPENFILE(SpisNach,SpisEnd);print(spisnach,nposition); GOTO PPP; END;

IF c1=#102 THEN BEGIN SEARCH(spisnach); Print(Spisnach, Nposition); GOTO PPP; END;

IF c1=#103 THEN BEGIN SORTBYGROUP(SpisNach); print(SpisNach,Nposition); GOTO PPP; END;

if c1=#97 then BEGIN SORTBYALBUM(SpisNach); print(SpisNach,Nposition); GOTO PPP; END;

if c1=#121 then BEGIN SORTBYYEAR(SpisNach); print(SpisNach,Nposition); GOTO PPP; END;

IF c1=#115 THEN BEGIN SORTBYSONG(SpisNach); print(SpisNach,Nposition); GOTO PPP; END;

IF c1=#116 THEN BEGIN SaveRecords(spisnach);print(spisnach,nposition); GOTO PPP; END;

IF c1=#100 THEN BEGIN {вызов процедуры удаления записи}

if Nposition>kzap then kzap:=kzap-1;

DelRecord(SpisNach,SpisEnd,Nposition);

if Nposition>kzap then Nposition:=Nposition-1;

print(spisnach,nposition); GOTO PPP; END;

IF c1=#112 THEN BEGIN

repeat {вызов процедуры добавления записи}

clrscr;

writeln('The menu of addition of record');

write('Enter the group name: ');

readln(gr1);

write('Enter the album name: ');

readln(al1);

write('Enter year of release of an album: ');

readln(ye1);

write('Enter a song: ');

readln(son1);

AddRecord(SpisNach,SpisEnd,gr1,al1,son1,ye1);

write('For an exit press "1"');

c1:=readkey;

until c1='1';

clrscr;

print(SpisNach,Nposition);

GOTO PPP; END;

if c1=#0 then begin {навигация по меню}

c1:=readkey;

if c1=#72 then begin

if Nposition>1 then begin

Nposition:=Nposition-1;

if Nposition<kzap then begin

textbackground(0);

textcolor(15);

print(SpisNach,Nposition);

end;

end;

end;

if c1=#80 then begin

if Nposition<Kzap then begin

Nposition:=Nposition+1;

print(SpisNach,Nposition);

end;

end;

end;

end;

clrscr;

FreeStek(spisnach);

gotoxy(74, 20);

write('ver 2.0');

readkey;

end.

Соседние файлы в предмете Основы алгоритмизации и программирования