Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Lab2;
- 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;
- 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, SecondName, Name, FatherName, Number);
- End
- Else
- ListElemPointer^.NextPointer := Nil;
- Writeln('-----------------------------------------------------');
- Until Choice = 0;
- 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