Advertisement
green1ant

3_2 file error

Nov 6th, 2018
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.51 KB | None | 0 0
  1. program Laba_3_1;
  2. {$APPTYPE CONSOLE}
  3. uses
  4.    SysUtils;
  5. type
  6.    TInputChoice = (TextFile, Console);
  7.    TSet = set of Char;
  8.  
  9. const
  10.    InstructionMessage
  11.       = 'This program composes a set consisting of arithmetic operands and even digits';
  12.    WayOfInputMessage = 'Where do you want to input data from? [F]ile or [C]onsole?';
  13.    IncorrectInputFilePath = 'Incoorrect input file path, check if file exists and try again';
  14.    IncorrectWayOfInputMessage = 'Incorrect way of input, choose [F]ile or [C]onsole';
  15.    Mask = '-+*/02468';
  16.  
  17. function GetInputFilePath(): string;//проверка на пустоту
  18. var
  19.    Path: string;
  20. begin
  21.    Writeln('Enter input file path');
  22.    Readln(Path);
  23.    while not FileExists(Path) do
  24.    begin
  25.       Writeln(IncorrectInputFilePath);
  26.       Readln(Path);
  27.    end;
  28.  
  29.    GetInputFilePath := Path;
  30. end;
  31.  
  32. function ChooseInputFromFileOrConsole(): TInputChoice;
  33. var
  34.    Choice: string;
  35. begin
  36.    Writeln(WayOfInputMessage);
  37.    Readln(Choice);
  38.    while (LowerCase(Choice) <> 'c') and (LowerCase(Choice) <> 'f') do
  39.    begin
  40.       Writeln(IncorrectWayOfInputMessage);
  41.       Readln(Choice);
  42.    end;
  43.  
  44.    if LowerCase(Choice) = 'f' then
  45.       ChooseInputFromFileOrConsole := TextFile
  46.    else
  47.       ChooseInputFromFileOrConsole := Console;
  48. end;
  49.  
  50. function GetSet(InputString: string): TSet;
  51. var
  52.    StringLength, i: Integer;
  53.    Sequence: TSet;
  54. begin
  55.    Sequence := [];
  56.    StringLength := Length(InputString);
  57.    for i := 1 to StringLength do
  58.       if (Pos(InputString[i], Mask) <> 0) and not(InputString[i] in Sequence) then
  59.          Include(Sequence, InputString[i]);//Sequence := Sequence + [InputString[i]];
  60.  
  61.    GetSet := Sequence;
  62. end;
  63.  
  64. procedure PrintSet(Sequence: TSet);
  65. var
  66.    i: Integer;
  67.    OutputFile: TextFile;
  68. begin
  69.    if Sequence = [] then
  70.       Writeln('Your sequence doesn''t contain any of assumed symbols')
  71.    else
  72.    begin
  73.       Writeln('Composed set based on your sequence');
  74.       for i := 0 to 255 do
  75.          if Chr(i) in Sequence then
  76.             Write(Chr(i), ' ');
  77.    end;
  78. end;
  79.  
  80. procedure Main();
  81. var
  82.    InputFilePath, InputString: string;
  83.    Sequence: TSet;
  84. begin
  85.    Writeln(InstructionMessage);
  86.    if ChooseInputFromFileOrConsole = TextFile then
  87.       //Writeln('input from file');
  88.       InputFilePath := GetInputFilePath()
  89.    else
  90.    begin
  91.       Writeln('Input sequence of symbols');
  92.       Readln(InputString);
  93.       Sequence := GetSet(InputString);
  94.       PrintSet(Sequence);
  95.    end;
  96.  
  97.    Readln;
  98. end;
  99.  
  100. begin
  101.    Main();
  102. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement