Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Project4;
- {$APPTYPE CONSOLE}
- Uses
- System.SysUtils;
- Type
- TSet = Set Of Char;
- Function Choose() : Boolean;
- Var
- InputNumber : Integer;
- IsCorrect : Boolean;
- Const
- MIN_NUM = 0;
- MAX_NUM = 1;
- Begin
- InputNumber := 0;
- Repeat
- IsCorrect := True;
- Try
- Readln(InputNumber)
- Except
- Writeln('Please, enter a integer number:');
- IsCorrect := False;
- End;
- If ((InputNumber < MIN_NUM) or (InputNumber > MAX_NUM)) then
- Begin
- Writeln('You are out of input range!');
- IsCorrect := False;
- End;
- Until IsCorrect;
- If (InputNumber = 1) then
- Choose := True
- Else
- Choose := False;
- End;
- Function InputFilePath() : String;
- Var
- IsCorrect : Boolean;
- Path : String;
- Begin
- Writeln('Input path to file: ');
- Repeat
- IsCorrect := True;
- Readln(Path);
- If(Not FileExists(Path)) Then
- Begin
- IsCorrect := False;
- Writeln('Wrong way to file. Input correct path.');
- End
- Else If (ExtractFileExt(Path) <> '.txt') Then
- Begin
- Writeln('Must have .txt');
- IsCorrect := False;
- End;
- Until IsCorrect;
- InputFilePath := Path;
- End;
- Function InputSequenceFromFile(Path : String): AnsiString;
- Var
- Sequence: AnsiString;
- InputFile: TextFile;
- IsCorrect : Boolean;
- Begin
- AssignFile(InputFile, Path);
- Reset(InputFile);
- Repeat
- IsCorrect := True;
- Try
- Readln(InputFile, Sequence);
- Except
- IsCorrect := False;
- Writeln('Mistake of reading string from file.');
- End;
- Until IsCorrect;
- CloseFile(InputFile);
- InputSequenceFromFile := Sequence;
- End;
- Function InputSequence(): AnsiString;
- Var
- Sequence: AnsiString;
- Begin
- Writeln('Enter Sequence');
- Readln(Sequence);
- InputSequence := Sequence;
- End;
- Function MakeSet(Sequence: AnsiString): TSet;
- Var
- I: Integer;
- SetOfSymbols: TSet;
- Const
- Symbols = ['/', '*', '-', '+', '%', '0' .. '9'];
- Begin
- SetOfSymbols := [];
- For I := 0 To Length(Sequence) Do
- If Sequence[I] In Symbols Then
- Include(SetOfSymbols, Sequence[I]);
- MakeSet := SetOfSymbols;
- End;
- Procedure ConsoleOutput(SetOfSymbols: TSet);
- Var
- I: Integer;
- Begin
- If SetOfSymbols = [] Then
- Write('You have not entered any signs of arithmetic operations or digits.')
- Else
- Begin
- Writeln('The resulting set');
- For I := 0 To 255 Do
- If chr(I) In SetOfSymbols Then
- Write(Chr(I), ' ');
- End;
- End;
- Procedure FileOutput(SetOfSymbols: TSet);
- Var
- IsCorrect: Boolean;
- OutputFile: TextFile;
- Path: String;
- I: Integer;
- Begin
- Path := InputFilePath();
- AssignFile(OutputFile, Path);
- Repeat
- IsCorrect := True;
- Try
- Rewrite(OutputFile);
- Except
- IsCorrect := False;
- Writeln('Mistake with writing in file. Input another path.');
- Path := InputFilePath();
- End;
- Until IsCorrect;
- If SetOfSymbols = [] Then
- Write(OutputFile, 'You have not entered any signs of arithmetic operations or digits.')
- Else
- Begin
- Writeln(OutputFile, 'The resulting set');
- For I := 0 To 255 Do
- If chr(I) In SetOfSymbols Then
- Write(OutputFile, Chr(I), ' ');
- End;
- CloseFile(OutputFile);
- Write('Output in file was successful.');
- End;
- Var
- SetOfSymbols : TSet;
- Sequence: AnsiString;
- Path: String;
- Chose : Boolean;
- Begin
- Writeln('The program builds and prints a set, the elements of which are the signs of arithmetic operations and numbers occurring in the sequence.');
- Writeln('Type 1 - console input, type 0 - file input.');
- Chose := Choose();
- If (Chose) Then
- Sequence := InputSequence
- Else
- Begin
- Path := InputFilePath();
- Sequence := InputSequenceFromFile(Path);
- End;
- SetOfSymbols := MakeSet(Sequence);
- Writeln('Type 1 - console output, type 0 - file output.');
- Chose := Choose();
- If (Chose) Then
- ConsoleOutput(SetOfSymbols)
- Else
- FileOutput(SetOfSymbols);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement