MaksNew

Untitled

Nov 7th, 2020
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.83 KB | None | 0 0
  1. Program Lab3_1;
  2.  
  3. Uses
  4.     System.SysUtils;
  5.  
  6. Var
  7.     Path: String;
  8.     Sentence: String;
  9.     Order: Integer;
  10.  
  11. Function GetFilePath(): String;
  12. Var
  13.     Path: String;
  14.     IsCorrect: Boolean;
  15. Begin
  16.     Repeat
  17.         Writeln('Введите абсолютный путь к файлу ');
  18.         Readln(Path);
  19.         IsCorrect := False;
  20.         If FileExists(Path) then
  21.         Begin
  22.                 Writeln('Файл успешно открыт');
  23.                 IsCorrect := true
  24.         End
  25.         Else
  26.             Writeln('Файл не найден');
  27.  
  28.     Until IsCorrect;
  29.     Result := Path;
  30. End;
  31.  
  32. Procedure GetFileToSentence(var Sentence:String; var Path: String);
  33. Var
  34.     I, J: Integer;
  35.     SenFile: TextFile;
  36. Begin
  37.     AssignFile(SenFile, Path);
  38.     Reset(SenFile);
  39.     Read(SenFile, Sentence);
  40.     CloseFile(SenFile);
  41. End;
  42.  
  43. Function GetOutput(): String;
  44. Var
  45.     Patho: String;
  46.     IsCorrect: Boolean;
  47. Begin
  48.     IsCorrect := False;
  49.     Repeat
  50.         Writeln('Введите директорию, в которую хотите сохранить исправленное предложение');
  51.         Readln(Patho);
  52.         If DirectoryExists(Patho) then
  53.             IsCorrect := True
  54.         Else
  55.             Writeln('Такой директории не существует. Попробуйте ещё раз');
  56.     Until IsCorrect;
  57.     Result := Patho;
  58. End;
  59.  
  60. Procedure GetSentenceToFile(Sentence: String);
  61. Var
  62.     I, J: Integer;
  63.     OutputFile: TextFile;
  64.     Directory: String;
  65. Begin
  66.     Directory := GetOutput();
  67.     AssignFile(OutputFile, Directory + '\output.txt');
  68.     Rewrite(OutputFile);
  69.     Write(OutputFile,Sentence);
  70.     Writeln(OutputFile);
  71.     Writeln('Результат сохранён по указанному пути');
  72.     CloseFile(OutputFile);
  73.     Write;
  74. End;
  75.  
  76.  
  77. Procedure PrintSentenceBO(Sentence: String);
  78. Begin
  79.     Writeln;
  80.     Writeln('Исходное предложение: ');
  81.     Write(Sentence);
  82.     Writeln;
  83. End;
  84.  
  85.  
  86. Function GetSentence(Sentence: String): String;
  87. Begin
  88.     While Sentence[1]=' ' do
  89.     Begin
  90.         Delete(Sentence, 1, 1);
  91.         While Pos('  ', Sentence) > 0 do
  92.         Begin
  93.             Delete(Sentence, Pos('  ', Sentence), 1);
  94.             While Sentence[Length(Sentence)] = ' ' do
  95.             Begin
  96.                 Delete(Sentence, Length(Sentence), 1);
  97.             End;
  98.         End;
  99.     End;
  100. Result := Sentence;
  101. End;
  102.  
  103. Procedure PrintSentencePO(Sentence: String);
  104. Begin
  105.     Writeln;
  106.     Writeln('Исправленное предложение:');
  107.     Writeln(Sentence);
  108.     Writeln;
  109. End;
  110.  
  111. Begin
  112.     Path := GetFilePath();
  113.     GetFileToSentence(Sentence, Path);
  114.     PrintSentenceBO(Sentence);
  115.     Sentence := GetSentence(Sentence);
  116.     PrintSentencePO(Sentence);
  117.     GetSentenceToFile(Sentence);
  118.     Readln;
  119. End.
Advertisement
Add Comment
Please, Sign In to add comment