Advertisement
green1ant

Non-functional case

Sep 26th, 2018
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.92 KB | None | 0 0
  1. program Project2;
  2. {$APPTYPE CONSOLE}
  3. {$R *.res}
  4. uses
  5.   System.SysUtils;
  6.  
  7. const
  8.    Amount = 5;
  9.    ErrorMessage = 'Error! Enter name (nonempty string, starts with uppercase letter)';
  10. function IsName(Name: string) : Boolean;
  11. var
  12.    NameLength, i : Integer;
  13.    HasSuchLetter : Boolean;
  14.    Alphabet : set of 'a'..'z';
  15. begin
  16.    Alphabet := ['a'..'z'];
  17.    NameLength := Length(Name);
  18.    IsName := True;
  19.  
  20.    if Name <> '' then
  21.       if Name[1] <> LowerCase(Name[1]) then
  22.          for i := 2 to NameLength do
  23.             if not (Name[i] in Alphabet) then
  24.                IsName := False
  25.       else
  26.          IsName := False
  27.    else
  28.       IsName := False;
  29. end;
  30.  
  31. var
  32.    MyName : string;
  33.    i, Counter, Index : Integer;
  34.    HasStarted, IsInvalid : Boolean;
  35.    List: array [0 .. 4] of string = ('Artem', 'Maxim', 'Arseniy', 'Vasya', 'Merlin');
  36.  
  37. begin
  38.    HasStarted := False;
  39.    IsInvalid := True;
  40.    Writeln('This program can recognize and greet one of 5 friends');
  41.    repeat
  42.       Counter := 0;
  43.       Index := -1;
  44.       while IsInvalid do
  45.          try
  46.             if not HasStarted then
  47.                Writeln('Enter name:')
  48.             else
  49.                Writeln('Please, clarify the name:');
  50.             Readln(MyName);
  51.             if (MyName = '') or (MyName[1] = LowerCase(MyName[1])) then
  52.                Writeln(ErrorMessage)
  53.             else
  54.                IsInvalid := False;
  55.          except
  56.             Writeln(ErrorMessage);
  57.          end;
  58.       IsInvalid := True;
  59.       for i := 0 to Amount - 1 do
  60.          if Pos(MyName, List[i]) = 1 then
  61.          begin
  62.             Counter := Counter + 1;
  63.             Index := i;
  64.          end;
  65.       Writeln('Matches found: ', Counter);
  66.       if Counter = 0 then
  67.          Counter := 1;
  68.       HasStarted := True;
  69.    until Counter = 1;
  70.    if Index = -1 then
  71.       Writeln('I DON''T KNOW YOU!')
  72.    else
  73.       Writeln(List[Index], ', nice to meet you!');
  74.    Readln;
  75. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement