Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- Uses
- System.SysUtils;
- Type
- TPointer = ^NumberList;
- NumberList = record
- Number: Integer;
- Name: String;
- SecondName: String;
- FatherName: String;
- NextPointer: TPointer;
- end;
- Function ReadNum(): Integer;
- Var
- N: Integer;
- IsCorrect: Boolean;
- Begin
- Repeat
- IsCorrect := True;
- Try
- Readln(N);
- Except
- IsCorrect := False;
- Writeln('Некорректный ввод! Введите семизначный номер!');
- End;
- If (IsCorrect) And ((N > 9999999)Or (N < 1000000)) then
- Begin
- IsCorrect := False;
- Writeln('Некорректный ввод! Введите семизначный номер!');
- End;
- ReadNum := N;
- Until IsCorrect;
- End;
- Function ReadChoice(Min, Max: Integer): Integer;
- Var
- N: Integer;
- IsCorrect: Boolean;
- Begin
- Repeat
- IsCorrect := True;
- Try
- Readln(N);
- Except
- IsCorrect := False;
- Writeln('Некорректный ввод! Попробуйте еще раз!');
- End;
- If(IsCorrect) And ((N > Max) Or (N < Min)) then
- Begin
- IsCorrect := False;
- Writeln('Некорректный ввод! Попробуйте еще раз!');
- End;
- ReadChoice := N;
- Until IsCorrect;
- End;
- Procedure CreateNewRecord(Pointer: TPointer; Name, SecondName, FatherName: String; Number: Integer);
- Begin
- Pointer^.Name := Name;
- Pointer^.SecondName := SecondName;
- Pointer^.FatherName := FatherName;
- Pointer^.Number := Number;
- End;
- Procedure OutputNumberRecord(Header: TPointer; Number: Integer);
- var
- IsFinded: Boolean;
- NextPointer: TPointer;
- Begin
- IsFinded := False;
- NextPointer := Header^.NextPointer;
- While(NextPointer^.NextPointer <> nil) do
- Begin
- if NextPointer^.Number = Number then
- Begin
- Writeln(NextPointer^.SecondName);
- IsFinded := True;
- End;
- NextPointer := NextPointer^.NextPointer;
- End;
- //последний элемент списка, у него NextPointer = nil
- if NextPointer^.Number = Number then
- Begin
- Writeln(NextPointer^.SecondName);
- IsFinded := True;
- End;
- if Not IsFinded then
- Writeln('Совпадений не найдено!');
- End;
- Procedure OutputSecondNameRecord(Header: TPointer; SecondName: String);
- var
- IsFinded: Boolean;
- NextPointer: TPointer;
- Begin
- IsFinded := False;
- NextPointer := Header^.NextPointer;
- While(NextPointer^.NextPointer <> nil) do
- Begin
- if NextPointer^.SecondName = SecondName then
- Begin
- Writeln(NextPointer^.Number);
- IsFinded := True;
- End;
- NextPointer := NextPointer^.NextPointer;
- End;
- //последний элемент списка, у него NextPointer = nil
- if NextPointer^.SecondName = SecondName then
- Begin
- Writeln(NextPointer^.Number);
- IsFinded := True;
- End;
- if not IsFinded then
- Writeln('Совпадений не найдено!');
- End;
- procedure InsertInList(RecordOfMan: NumberList; Header : TPointer);
- var
- Temp: TPointer;
- IsInsert: Boolean;
- begin
- IsInsert := False;
- while Not IsInsert do
- begin
- if (Header^.NextPointer = nil) or (RecordOfMan.SecondName < Header^.NextPointer^.SecondName) then
- begin
- Temp := Header^.NextPointer;
- New(Header^.NextPointer);
- Header := Header^.NextPointer;
- Header^.SecondName := RecordOfMan.SecondName;
- Header^.Name := RecordOfMan.Name;
- Header^.FatherName := RecordOfMan.FatherName;
- Header^.Number := RecordOfMan.Number;
- Header^.NextPointer := Temp;
- IsInsert := True;
- end
- else
- Header := Header^.NextPointer;
- end;
- end;
- Procedure WriteSingleList(Header: TPOinter);
- var
- Y, FirstListEl: TPointer;
- NextNum: String;
- begin
- Header := Header.NextPointer;
- New(FirstListEl);
- FirstListEl^.NextPointer := nil;
- while Header <> nil do
- begin
- InsertInList(Header^, FirstListEl);
- Header := Header^.NextPointer;
- end;
- FirstListEl := FirstListEl.NextPointer;
- while FirstListEl <> nil do
- Begin
- Write('Фамилия: ', FirstListEl^.SecondName,' ', 'Имя: ', FirstListEl^.Name,' ','Отчество: ', FirstListEl^.FatherName,' ', 'Номер телефона:',' ', FirstListEL^.Number);
- FirstListEl := FirstListEl.NextPointer;
- Writeln;
- End;
- end;
- Var
- Number, Choice: Integer;
- Name, SecondName, FatherName: String;
- Header, ListElemPointer: TPointer;
- begin
- New(Header);
- Header^.NextPointer := nil;
- ListElemPointer := Header;
- Repeat
- Writeln('Добавить новую запись - 1, завершить ввод - 0:');
- Writeln('-----------------------------------------------------');
- Choice := ReadChoice(0, 1);
- if Choice <> 0 then
- Begin
- New(ListElemPointer^.NextPointer);
- ListElemPointer := ListElemPointer^.NextPointer;
- Write('Введите фамилию: ');
- Readln(SecondName);
- Write('Введите имя: ');
- Readln(Name);
- Write('Введите отчество: ');
- Readln(FatherName);
- Write('Введите семизначный номер телефона: ');
- Number := ReadNum();
- CreateNewRecord(ListElemPointer, Name, SecondName, FatherName, Number);
- End
- Else
- ListElemPointer^.NextPointer := Nil;
- Writeln('-----------------------------------------------------');
- Until Choice = 0;
- WriteSingleList(Header);
- Writeln('Выберите действие со списком:');
- Repeat
- Writeln('0 - выход, 1 - поиск по фамилии, 2 - поиск по номеру:');
- Writeln('-----------------------------------------------------');
- Choice := ReadChoice(0, 2);
- case Choice of
- 1:
- Begin
- If Header^.NextPointer = nil then
- Writeln('Список номеров пуст!')
- Else
- Begin
- Write('Введите фамилию: ');
- Readln(SecondName);
- OutputSecondNameRecord(Header, SecondName);
- End;
- End;
- 2:
- Begin
- If Header^.NextPointer = nil then
- Writeln('Список номеров пуст!')
- Else
- Begin
- Write('Введите номер: ');
- Number := ReadNum();
- OutputNumberRecord(Header, Number);
- End;
- End;
- end;
- Writeln('-----------------------------------------------------');
- Until Choice = 0;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement