SHARE
TWEET

Untitled

a guest May 19th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function checkUserInput(userString: string): boolean;
  2. var
  3.   valid: boolean;
  4.   count: integer;
  5. begin
  6.   valid := true;
  7.   for count := 1 to length(userString) do
  8.     if ((ord(userString[count]) < 65) or (ord(userString[count]) > 90)) and (userString[count] <> ' ') then
  9.       valid := false;
  10.   checkUserInput := valid;
  11. end;
  12.  
  13. function getCharacterCode(character: char): string;
  14. const
  15.   translationArray: array [0..25] of string = ('.-', '-...', '-.-.', '-..', '.', '..-.', '--.', '....', '..', '.---', '-.-', '.-..', '--', '-.', '---', '.--.', '--.-', '.-.', '...', '-', '..-', '...-', '.--', '-..-', '-.--', '--..');
  16. begin
  17.   if character = ' ' then
  18.     getCharacterCode := '| '
  19.   else
  20.     begin
  21.       getCharacterCode := translationArray[ord(character) - 65] + ' ';
  22.     end;
  23. end;
  24.  
  25. procedure main();
  26. var
  27.   userString, codedString: string;
  28.   count: integer;
  29. begin
  30.   write('Enter a string: ');
  31.   readln(userString);
  32.   if checkUserInput(upcase(userString)) then
  33.     begin
  34.       for count := 1 to length(userString) do
  35.         begin
  36.           codedString := concat(codedString, getCharacterCode(upcase(userString[count])));
  37.         end;
  38.       writeln(codedString);
  39.     end
  40.   else
  41.     writeln('Invalid input!');
  42. end;
  43.  
  44. begin
  45.   main();
  46.   readln;
  47. end.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top