Добавил:
Eatmore
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:написанные программы / задание №6 — 2 / BUSPARK
.PAS Program Bus_Park;
{ Їа®Ја ¬¬ ¤¬ЁЁбваЁа®ў Ёп ўв®Ўгб®Ј® Ї аЄ }
Uses CRT;
Type
{ ўв®Ўгб }
TBus = Record
N: LongInt;
Name: String[20];
NBus: Word;
end;
{ Ї аЄ ўв®Ўгб®ў }
PPark=^TPark;
TPark = Record
Bus: TBus;
pNext: PPark;
end;
{ 'г«Ґў®©' ўв®Ўгб }
Const nilBus: TBus = (n:0);
Var
pBeginIn, pEndIn, pBeginOut, pEndOut: PPark;
pAux, pCKey, pPreComp: PPark;
Bus: TBus;
FilePark: Text;
c: Char;
mQiut: Boolean;
{ ўў®¤ ўв®Ўгб б Є« ўЁ вгал }
Procedure ReadBus(Var iBus: TBus);
Begin
Write('‚ўҐ¤ЁвҐ ®¬Ґа ўв®Ўгб : '); ReadLn(iBus.N);
Write('‚ўҐ¤ЁвҐ д ¬Ё«Ёо ў®¤ЁвҐ«п: '); ReadLn(iBus.Name);
Write('‚ўҐ¤ЁвҐ ¬ аиагв ўв®Ўгб : '); ReadLn(iBus.NBus);
End;
{ ўлў®¤ ўв®Ўгб ¬®Ёв®а }
Procedure WriteBus(Var iBus: TBus);
Begin
if iBus.N<>0 then
begin
Write(' ўв®Ўгб #',iBus.N,', ');
Write('ў®¤ЁвҐ«м ',iBus.Name,', ');
WriteLn('¬ аиагв ',iBus.NBus,' ;');
end
else
WriteLn('Ў®«миҐ Ґв');
End;
{ б®®ЎйҐЁҐ }
Procedure isEnd;
Begin
WriteLn;
Write('‚бҐ. «ҐЇЁ …вҐа'); ReadLn;
End;
{ ЁЁжЁ «Ё§ жЁп Ї аЄ }
Procedure InitPark(Var pBegin, pEnd: PPark);
Begin
New(pBegin);
pBegin^.pNext:=nil;
pBegin^.Bus:=nilBus;
pEnd:=pBegin;
End;
{ ᮧ¤ ЁҐ Ї аЄ }
Procedure CreatePark(Var pBegin, pEnd: PPark; Var cBus: TBus);
begin
New(pBegin);
pBegin^.pNext:=nil;
pBegin^.Bus:=cBus;
pEnd:=pBegin;
end;
{ ¤®Ў ў«ҐЁҐ ўв®Ўгб }
Procedure AddBus(Var pEnd: PPark; Var cBus: TBus);
begin
New(pAux);
pAux^.pNext:=Nil;
pEnd^.pNext:=pAux;
pEnd:=pAux;
pEnd^.Bus:=cBus;
end;
{ Ї®ЁбЄ ўв®Ўгб Ї® ®¬Ґаг }
Function Find(Var sKey: LongInt; Var pBegin, pCkey, pPreComp: PPark): Boolean;
begin
pCKey:=pBegin;
While pCKey <> nil do
begin
if pCKey^.Bus.N = sKey then
begin
Find:=True;
exit
end;
pPreComp:=pCKey;
pCKey:=pCKey^.pNext
end;
Find:=False;
end;
{ г¤ «ҐЁҐ ўв®Ўгб Ё§ бЇЁбЄ }
Procedure DelBus(Var sKey: LongInt; var pBegin: PPark; Var fBus: TBus);
begin
if not Find(sKey, pBegin, pCKey, pPreComp) then exit;
if pCkey=pBegin then
pBegin:=pCKey^.pNext
else
pPreComp^.pNext:=pCKey^.pNext;
fBus:=pCKey^.Bus;
Dispose(pCKey);
end;
{ ®б®ў п Їа®Ја ¬¬ }
Begin
mQiut:=False;
InitPark(pBeginOut, pEndOut);
InitPark(pBeginIn, pEndIn);
Assign(FilePark,'buspark.txt');
Reset(FilePark);
TextColor(0);
Window(1,1,80,6);
TextBackGround(magenta);
ClrScr;
WriteLn(' ЪДНННННННННННННННННННННННННННННННННННННННННННННННННННННННДї');
WriteLn(' є B U S P A R K A D M I N I S T R A T O R є');
WriteLn(' АДННННННННННННННННННННННН ‚лЎЁа ©вҐ НННННННННННННННННННННДЩ');
WriteLn;
WriteLn(' | Keyb | File | Input | Output | List | Rest | Work | eXit |');
Window(1,7,80,25);
TextBackGround(15);
Repeat
ClrScr;
c:=ReadKey;
case c of
'f':
Begin
WriteLn('***** ‚ў®¤ ўбҐе ўв®Ўгб®ў Ё§ д ©« *****');
WriteLn;
Read(FilePark, Bus.N);
Read(FilePark, Bus.Name);
Read(FilePark, Bus.NBus);
CreatePark(pBeginIn, pEndIn, Bus);
WriteLn;
While (Bus.Name<>'end') and (not Eof(FilePark)) do
Begin
Read(FilePark, Bus.N);
Read(FilePark, Bus.Name);
Read(FilePark, Bus.NBus);
if Bus.Name<>'end' then AddBus(pEndIn, Bus)
End;
isEnd;
End;
'k':
Begin
WriteLn('***** ‚ў®¤ ўбҐе ўв®Ўгб®ў б Є« ўЁ вгал *****');
WriteLn;
WriteLn('¤«п § ўҐаиҐЁп ўў®¤ ўўҐ¤ЁвҐ "end" ў Ё¬ҐЁ ў®¤ЁвҐ«п');
ReadBus(Bus);
CreatePark(pBeginIn, pEndIn, Bus);
WriteLn;
While (Bus.Name<>'end') and (not Eof(FilePark)) do
Begin
ReadBus(Bus);
WriteLn;
if Bus.Name<>'end' then AddBus(pEndIn, Bus)
End;
isEnd;
End;
'i':
Begin
WriteLn('***** ўкҐ§¤ ўв®Ўгб ў Ї аЄ *****');
Write('ўўҐ¤ЁвҐ ®¬Ґа: '); ReadLn(Bus.N);
if Find(Bus.N, pBeginOut, pCkey, pPreComp) then
begin
DelBus(Bus.N, pBeginOut, Bus);
AddBus(pEndIn, Bus);
WriteLn('Ёд®а¬ жЁп ®Ў®ў«Ґ ');
end
else
WriteLn('г б ¦Ґ Ґв в Є®Ј® ўв®Ўгб ');
isEnd;
End;
'o':
Begin
WriteLn('***** ўлҐ§¤ ўв®Ўгб Ё§ Ї аЄ *****');
Write('ўўҐ¤ЁвҐ ®¬Ґа: '); ReadLn(Bus.N);
if Find(Bus.N, pBeginIn, pCkey, pPreComp) then
begin
DelBus(Bus.N, pBeginIn, Bus);
AddBus(pEndOut, Bus);
WriteLn('Ёд®а¬ жЁп ®Ў®ў«Ґ ');
end
else
WriteLn('г б ¦Ґ Ґв в Є®Ј® ўв®Ўгб ');
isEnd;
End;
'l':
Begin
WriteLn('***** «ЁбвЁЈ ўв®Ўгб®ў *****');
WriteLn;
WriteLn(' ўв®Ўгбл ¬ аиагвҐ: ');
pAux:=pBeginOut;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
WriteLn(' ўв®Ўгбл ў Ї аЄҐ: ');
pAux:=pBeginIn;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
isEnd;
End;
'w':
Begin
WriteLn('***** ўв®Ўгбл ¬ аиаг⥠*****');
pAux:=pBeginOut;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
isEnd;
End;
'r':
Begin
WriteLn('***** ўв®Ўгбл ў Ї аЄҐ *****');
pAux:=pBeginIn;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
isEnd;
End;
'x': mQiut:= True;
End;
Until mQiut=True;
Close(FilePark);
end.
{ Їа®Ја ¬¬ ¤¬ЁЁбваЁа®ў Ёп ўв®Ўгб®Ј® Ї аЄ }
Uses CRT;
Type
{ ўв®Ўгб }
TBus = Record
N: LongInt;
Name: String[20];
NBus: Word;
end;
{ Ї аЄ ўв®Ўгб®ў }
PPark=^TPark;
TPark = Record
Bus: TBus;
pNext: PPark;
end;
{ 'г«Ґў®©' ўв®Ўгб }
Const nilBus: TBus = (n:0);
Var
pBeginIn, pEndIn, pBeginOut, pEndOut: PPark;
pAux, pCKey, pPreComp: PPark;
Bus: TBus;
FilePark: Text;
c: Char;
mQiut: Boolean;
{ ўў®¤ ўв®Ўгб б Є« ўЁ вгал }
Procedure ReadBus(Var iBus: TBus);
Begin
Write('‚ўҐ¤ЁвҐ ®¬Ґа ўв®Ўгб : '); ReadLn(iBus.N);
Write('‚ўҐ¤ЁвҐ д ¬Ё«Ёо ў®¤ЁвҐ«п: '); ReadLn(iBus.Name);
Write('‚ўҐ¤ЁвҐ ¬ аиагв ўв®Ўгб : '); ReadLn(iBus.NBus);
End;
{ ўлў®¤ ўв®Ўгб ¬®Ёв®а }
Procedure WriteBus(Var iBus: TBus);
Begin
if iBus.N<>0 then
begin
Write(' ўв®Ўгб #',iBus.N,', ');
Write('ў®¤ЁвҐ«м ',iBus.Name,', ');
WriteLn('¬ аиагв ',iBus.NBus,' ;');
end
else
WriteLn('Ў®«миҐ Ґв');
End;
{ б®®ЎйҐЁҐ }
Procedure isEnd;
Begin
WriteLn;
Write('‚бҐ. «ҐЇЁ …вҐа'); ReadLn;
End;
{ ЁЁжЁ «Ё§ жЁп Ї аЄ }
Procedure InitPark(Var pBegin, pEnd: PPark);
Begin
New(pBegin);
pBegin^.pNext:=nil;
pBegin^.Bus:=nilBus;
pEnd:=pBegin;
End;
{ ᮧ¤ ЁҐ Ї аЄ }
Procedure CreatePark(Var pBegin, pEnd: PPark; Var cBus: TBus);
begin
New(pBegin);
pBegin^.pNext:=nil;
pBegin^.Bus:=cBus;
pEnd:=pBegin;
end;
{ ¤®Ў ў«ҐЁҐ ўв®Ўгб }
Procedure AddBus(Var pEnd: PPark; Var cBus: TBus);
begin
New(pAux);
pAux^.pNext:=Nil;
pEnd^.pNext:=pAux;
pEnd:=pAux;
pEnd^.Bus:=cBus;
end;
{ Ї®ЁбЄ ўв®Ўгб Ї® ®¬Ґаг }
Function Find(Var sKey: LongInt; Var pBegin, pCkey, pPreComp: PPark): Boolean;
begin
pCKey:=pBegin;
While pCKey <> nil do
begin
if pCKey^.Bus.N = sKey then
begin
Find:=True;
exit
end;
pPreComp:=pCKey;
pCKey:=pCKey^.pNext
end;
Find:=False;
end;
{ г¤ «ҐЁҐ ўв®Ўгб Ё§ бЇЁбЄ }
Procedure DelBus(Var sKey: LongInt; var pBegin: PPark; Var fBus: TBus);
begin
if not Find(sKey, pBegin, pCKey, pPreComp) then exit;
if pCkey=pBegin then
pBegin:=pCKey^.pNext
else
pPreComp^.pNext:=pCKey^.pNext;
fBus:=pCKey^.Bus;
Dispose(pCKey);
end;
{ ®б®ў п Їа®Ја ¬¬ }
Begin
mQiut:=False;
InitPark(pBeginOut, pEndOut);
InitPark(pBeginIn, pEndIn);
Assign(FilePark,'buspark.txt');
Reset(FilePark);
TextColor(0);
Window(1,1,80,6);
TextBackGround(magenta);
ClrScr;
WriteLn(' ЪДНННННННННННННННННННННННННННННННННННННННННННННННННННННННДї');
WriteLn(' є B U S P A R K A D M I N I S T R A T O R є');
WriteLn(' АДННННННННННННННННННННННН ‚лЎЁа ©вҐ НННННННННННННННННННННДЩ');
WriteLn;
WriteLn(' | Keyb | File | Input | Output | List | Rest | Work | eXit |');
Window(1,7,80,25);
TextBackGround(15);
Repeat
ClrScr;
c:=ReadKey;
case c of
'f':
Begin
WriteLn('***** ‚ў®¤ ўбҐе ўв®Ўгб®ў Ё§ д ©« *****');
WriteLn;
Read(FilePark, Bus.N);
Read(FilePark, Bus.Name);
Read(FilePark, Bus.NBus);
CreatePark(pBeginIn, pEndIn, Bus);
WriteLn;
While (Bus.Name<>'end') and (not Eof(FilePark)) do
Begin
Read(FilePark, Bus.N);
Read(FilePark, Bus.Name);
Read(FilePark, Bus.NBus);
if Bus.Name<>'end' then AddBus(pEndIn, Bus)
End;
isEnd;
End;
'k':
Begin
WriteLn('***** ‚ў®¤ ўбҐе ўв®Ўгб®ў б Є« ўЁ вгал *****');
WriteLn;
WriteLn('¤«п § ўҐаиҐЁп ўў®¤ ўўҐ¤ЁвҐ "end" ў Ё¬ҐЁ ў®¤ЁвҐ«п');
ReadBus(Bus);
CreatePark(pBeginIn, pEndIn, Bus);
WriteLn;
While (Bus.Name<>'end') and (not Eof(FilePark)) do
Begin
ReadBus(Bus);
WriteLn;
if Bus.Name<>'end' then AddBus(pEndIn, Bus)
End;
isEnd;
End;
'i':
Begin
WriteLn('***** ўкҐ§¤ ўв®Ўгб ў Ї аЄ *****');
Write('ўўҐ¤ЁвҐ ®¬Ґа: '); ReadLn(Bus.N);
if Find(Bus.N, pBeginOut, pCkey, pPreComp) then
begin
DelBus(Bus.N, pBeginOut, Bus);
AddBus(pEndIn, Bus);
WriteLn('Ёд®а¬ жЁп ®Ў®ў«Ґ ');
end
else
WriteLn('г б ¦Ґ Ґв в Є®Ј® ўв®Ўгб ');
isEnd;
End;
'o':
Begin
WriteLn('***** ўлҐ§¤ ўв®Ўгб Ё§ Ї аЄ *****');
Write('ўўҐ¤ЁвҐ ®¬Ґа: '); ReadLn(Bus.N);
if Find(Bus.N, pBeginIn, pCkey, pPreComp) then
begin
DelBus(Bus.N, pBeginIn, Bus);
AddBus(pEndOut, Bus);
WriteLn('Ёд®а¬ жЁп ®Ў®ў«Ґ ');
end
else
WriteLn('г б ¦Ґ Ґв в Є®Ј® ўв®Ўгб ');
isEnd;
End;
'l':
Begin
WriteLn('***** «ЁбвЁЈ ўв®Ўгб®ў *****');
WriteLn;
WriteLn(' ўв®Ўгбл ¬ аиагвҐ: ');
pAux:=pBeginOut;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
WriteLn(' ўв®Ўгбл ў Ї аЄҐ: ');
pAux:=pBeginIn;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
isEnd;
End;
'w':
Begin
WriteLn('***** ўв®Ўгбл ¬ аиаг⥠*****');
pAux:=pBeginOut;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
isEnd;
End;
'r':
Begin
WriteLn('***** ўв®Ўгбл ў Ї аЄҐ *****');
pAux:=pBeginIn;
Repeat
WriteBus(pAux^.Bus);
pAux:=pAux^.pNext;
Until pAux=Nil;
isEnd;
End;
'x': mQiut:= True;
End;
Until mQiut=True;
Close(FilePark);
end.
Соседние файлы в папке задание №6 — 2