Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Laba_3_1;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- type
- TInputChoice = (TextFile, Console);
- TSet = set of Char;
- const
- InstructionMessage
- = 'This program composes a set consisting of arithmetic operands and even digits';
- WayOfInputMessage = 'Where do you want to input data from? [F]ile or [C]onsole?';
- IncorrectInputFilePath = 'Incoorrect input file path, check if file exists and try again';
- IncorrectWayOfInputMessage = 'Incorrect way of input, choose [F]ile or [C]onsole';
- Mask = '-+*/02468';
- function GetInputFilePath(): string;//проверка на пустоту
- var
- Path: string;
- begin
- Writeln('Enter input file path');
- Readln(Path);
- while not FileExists(Path) do
- begin
- Writeln(IncorrectInputFilePath);
- Readln(Path);
- end;
- GetInputFilePath := Path;
- end;
- function ChooseInputFromFileOrConsole(): TInputChoice;
- var
- Choice: string;
- begin
- Writeln(WayOfInputMessage);
- Readln(Choice);
- while (LowerCase(Choice) <> 'c') and (LowerCase(Choice) <> 'f') do
- begin
- Writeln(IncorrectWayOfInputMessage);
- Readln(Choice);
- end;
- if LowerCase(Choice) = 'f' then
- ChooseInputFromFileOrConsole := TextFile
- else
- ChooseInputFromFileOrConsole := Console;
- end;
- function GetSet(InputString: string): TSet;
- var
- StringLength, i: Integer;
- Sequence: TSet;
- begin
- Sequence := [];
- StringLength := Length(InputString);
- for i := 1 to StringLength do
- if (Pos(InputString[i], Mask) <> 0) and not(InputString[i] in Sequence) then
- Include(Sequence, InputString[i]);//Sequence := Sequence + [InputString[i]];
- GetSet := Sequence;
- end;
- procedure PrintSet(Sequence: TSet);
- var
- i: Integer;
- OutputFile: TextFile;
- begin
- if Sequence = [] then
- Writeln('Your sequence doesn''t contain any of assumed symbols')
- else
- begin
- Writeln('Composed set based on your sequence');
- for i := 0 to 255 do
- if Chr(i) in Sequence then
- Write(Chr(i), ' ');
- end;
- end;
- procedure Main();
- var
- InputFilePath, InputString: string;
- Sequence: TSet;
- begin
- Writeln(InstructionMessage);
- if ChooseInputFromFileOrConsole = TextFile then
- //Writeln('input from file');
- InputFilePath := GetInputFilePath()
- else
- begin
- Writeln('Input sequence of symbols');
- Readln(InputString);
- Sequence := GetSet(InputString);
- PrintSet(Sequence);
- end;
- Readln;
- end;
- begin
- Main();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement