Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program Lab3_1;
- Uses
- System.SysUtils;
- type
- InputType = (FromConsole, FromFile);
- Var
- Path: String;
- Sentence: String;
- Order: Integer;
- function GetInputType(): InputType;
- var
- Ret: InputType;
- Input: String;
- IsCorrect: Boolean;
- begin
- IsCorrect := False;
- repeat
- Writeln('Выберите способ ввода предложения файл/консоль (ф/к)');
- Readln(Input);
- if (Input = 'ф') or (Input = 'Ф') or (Input = 'Файл') or (Input = 'файл')
- then
- begin
- Ret := InputType.FromFile;
- IsCorrect := True;
- end
- else if (Input = 'к') or (Input = 'К') or (Input = 'Консоль') or
- (Input = 'консоль') then
- begin
- Ret := InputType.FromConsole;
- IsCorrect := True;
- end;
- until IsCorrect;
- Result := Ret;
- end;
- function GetSentenceFromConsole(var Sentence:String): String;
- begin
- Writeln('Введите исходное предложение');
- Readln(Sentence);
- Result := Sentence;
- end;
- Function GetFilePath(): String;
- Var
- Path: String;
- IsCorrect: Boolean;
- Begin
- Repeat
- Writeln('Введите абсолютный путь к файлу ');
- Readln(Path);
- IsCorrect := False;
- If FileExists(Path) then
- Begin
- Writeln('Файл успешно открыт');
- IsCorrect := true
- End
- Else
- Writeln('Файл не найден');
- Until IsCorrect;
- Result := Path;
- End;
- Function GetSentenceFromFile(Var Sentence:String): String;
- Var
- SenFile: TextFile;
- Begin
- Path := GetFilePath();
- AssignFile(SenFile, Path);
- Reset(SenFile);
- Read(SenFile, Sentence);
- CloseFile(SenFile);
- Result := Sentence;
- End;
- Procedure PrintSentenceBeforeEditing(Sentence: String);
- Begin
- Writeln;
- Writeln('Исходное предложение: ');
- Write(Sentence);
- Writeln;
- End;
- function GetSentence(): String;
- var
- SelectedInputType: InputType;
- begin
- SelectedInputType := GetInputType();
- if (SelectedInputType = InputType.FromConsole) then
- begin
- Sentence := GetSentenceFromConsole(Sentence)
- end
- else if (SelectedInputType = InputType.FromFile) then
- begin
- Sentence := GetSentenceFromFile(Sentence);
- end;
- PrintSentenceBeforeEditing(Sentence);
- Result := Sentence;
- end;
- Function Output(): String;
- Var
- Patho: String;
- IsCorrect: Boolean;
- Begin
- IsCorrect := False;
- Repeat
- Writeln('Введите директорию, в которую хотите сохранить исправленное предложение');
- Readln(Patho);
- If DirectoryExists(Patho) then
- IsCorrect := True
- Else
- Writeln('Такой директории не существует. Попробуйте ещё раз');
- Until IsCorrect;
- Result := Patho;
- End;
- Procedure SaveSentenceToFile(Sentence: String);
- Var
- I, J: Integer;
- OutputFile: TextFile;
- Directory: String;
- Begin
- Directory := Output();
- AssignFile(OutputFile, Directory + '\output.txt');
- Rewrite(OutputFile);
- Write(OutputFile,Sentence);
- Writeln(OutputFile);
- Writeln('Результат сохранён по указанному пути');
- CloseFile(OutputFile);
- Write;
- End;
- Procedure PrintSentenceAfterEditing(Sentence: String);
- Begin
- Writeln;
- Writeln('Исправленное предложение:');
- Writeln(Sentence);
- Writeln;
- End;
- Function Editing(Sentence: String): String;
- Var
- I:Integer;
- Begin
- While Sentence[1]=' ' do
- Begin
- Delete(Sentence, 1, 1);
- End;
- While Pos(' ', Sentence) > 0 do
- Begin
- Delete(Sentence, Pos(' ', Sentence), 1);
- End;
- While Sentence[Length(Sentence)] = ' ' do
- Begin
- Delete(Sentence, Length(Sentence), 1);
- End;
- for I := 0 to Length(Sentence) do
- if ((Sentence[I] in [',', '.', '?', '!', ';', ':']) and (Sentence[I-1]=' ')) then
- Delete(Sentence, I-1, 1);
- Editing(Sentence);
- Result := Sentence;
- End;
- Begin
- Sentence := GetSentence();
- Sentence := Editing(Sentence);
- SaveSentenceToFile(Sentence);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment