Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program laba31;
- uses
- System.SysUtils;
- function Choic : Boolean;
- var Console, IsntCorrect : Boolean;
- Choice : Char;
- begin
- IsntCorrect := True;
- While(IsntCorrect) do
- begin
- WriteLn('If you want to enter data from the console, enter Y or y, and if from the file, enter N or n');
- ReadLn(Choice);
- if (Choice = 'Y') or (Choice = 'y') or (Choice = 'N') or (Choice = 'n') then
- begin
- IsntCorrect := False;
- if (Choice = 'Y') or (Choice = 'y') then
- Console := True
- else Console := False;
- end
- else
- begin
- IsntCorrect := True;
- WriteLn('This is mistake');
- end;
- end;
- choic := Console;
- end;
- function OpenFile : String;
- var
- Line : String;
- IsCorrect : Boolean;
- FileIn : TextFile;
- begin
- repeat
- WriteLn('Enter file location');
- ReadLn(Line);
- try
- AssignFile(FileIn, Line);
- Reset(FileIn);
- if FileExists(Line) then
- IsCorrect := True
- else
- begin
- WriteLn('Can not open this file. Please enter the name again');
- IsCorrect := False;
- end;
- except
- WriteLn('Can not open this file');
- end;
- until(IsCorrect);
- OpenFile := Line;
- end;
- function EnterText : String;
- var Text : String;
- begin
- WriteLn('Enter the text. All special characters and numbers such as 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, /, -, _, =, +, @, #, $, %, ^, &, *, (, ) will be deleted.');
- ReadLn(Text);
- EnterText := Text;
- end;
- function EnterFileText : String;
- var FileIn : TextFile;
- Text, Line : String;
- begin
- Line := OpenFile;
- AssignFile(FileIn, Line);
- Reset(FileIn);
- while (not EOF(FileIn)) do
- Readln(FileIn, Text);
- CloseFile(FileIn);
- EnterFileText := Text;
- end;
- function EditText(Choise : Boolean) : String;
- type
- InvalidValues = set of char;
- var Lengt, I : Integer;
- InvalidData, Data : InvalidValues;
- Text : String;
- begin
- Data := ['!', ';', ':', ',', '.', '?'];
- InvalidData := ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '"', ']', '}', '}', '[', '/', '-', '_', '=', '+', '@', '#', '$', '%', '^', '&', '*', '(', ')'];
- if Choise then
- Text := EnterText
- else
- Text := EnterFileText;
- Lengt := Length(Text);
- I := 1;
- while (I <= Lengt) do
- begin
- if Text[I] in InvalidData then
- begin
- Delete(Text, I, 1);
- Dec(Lengt);
- Dec(I);
- end;
- if (Text[I] = ' ') and (Text[I - 1] = ' ') then
- begin
- Delete(Text, I, 1);
- Dec(Lengt);
- Dec(I);
- end;
- if (Text[I] in Data) and (Text[I - 1] in Data) then
- begin
- Delete(Text, I, 1);
- Dec(Lengt);
- Dec(I);
- end;
- Inc(I);
- end;
- editText := Text;
- end;
- procedure Encryption (Choice : Boolean);
- type
- Values = set of Char;
- var FileOut : TextFile;
- Text, Temp : String;
- Lengt, I, Count, Parity : Integer;
- Data : Values;
- begin
- Data := ['!', ';', ':', ',', '.', '?'];
- Text := EditText(Choice);
- Lengt := Length(Text);
- Count := 0;
- I := 1;
- while (I <= Lengt) do
- begin
- Count := Count + 1;
- if (Text[I] = ' ') then
- begin
- Parity := Parity + 1;
- if Parity mod 2 = 0 then
- begin
- Temp := Copy(Text, I - (Count - 1), Count - 1);
- Delete(Text, I - (Count - 1), Count - 1);
- Insert(AnsiUpperCase(Temp), Text, I - (Count - 1));
- Count := 0;
- end
- else
- begin
- Insert('(', Text, I - (Count - 1));
- Insert(')', Text, I + 1);
- Lengt := Lengt + 2;
- I := I + 2;
- Count := 0;
- end;
- if (Text[I + 1] in Data) then Inc(I);
- end;
- if (Text[I] in Data) and (I < Lengt) and (Text[I - 1] <> ' ') then
- begin
- Parity := Parity + 1;
- if Parity mod 2 = 0 then
- begin
- Temp := Copy(Text, I - (Count - 1), Count - 1);
- Delete(Text, I - (Count - 1), Count - 1);
- Insert(AnsiUpperCase(Temp), Text, I - (Count - 1));
- Count := 0;
- end
- else
- begin
- Insert('(', Text, I - (Count - 1));
- Insert(')', Text, I + 1);
- Count := 0;
- Lengt := Lengt + 2;
- I := I + 2;
- end;
- if (Text[I + 1] = ' ') then Inc(I);
- end;
- if (I = Lengt) and (Text[I] in Data) then
- begin
- Parity := Parity + 1;
- if Parity mod 2 = 0 then
- begin
- Temp := Copy(Text, I - (Count - 1), Count - 1);
- Delete(Text, I - (Count - 1), Count - 1);
- Insert(AnsiUpperCase(Temp), Text, I - (Count - 1));
- Count := 0;
- end
- else
- begin
- Lengt := Lengt + 2;
- Insert('(', Text, I - (Count - 1));
- Insert(')', Text, I + 1);
- Count := 0;
- end;
- end
- else
- begin
- if I = Lengt then
- begin
- Parity := Parity + 1;
- if Parity mod 2 = 0 then
- begin
- Temp := Copy(Text, I - Count, Count + 1);
- Delete(Text, I - Count, Count + 1);
- Insert(AnsiUpperCase(Temp), Text, I - Count);
- Count := 0;
- end
- else
- begin
- Insert('(', Text, I - (Count - 1));
- Insert(')', Text, I + 4);
- Lengt := Lengt + 2;
- I := I + 2;
- Count := 0;
- end;
- end
- end;
- Inc(I);
- end;
- WriteLn(Text);
- if Choice = False then
- begin
- AssignFile(FileOut, 'D:\output.txt');
- Rewrite(FileOut);
- Writeln(FileOut,Text);
- CloseFile(FileOut);
- end;
- ReadLn;
- ReadLn;
- end;
- procedure main;
- var Choice : Boolean;
- begin
- Choice := Choic;
- Encryption(Choice);
- end;
- begin
- WriteLn('This program in the text in every even word replaces all lowercase alphabetic characters with uppercase, and each odd word is enclosed in parentheses');
- Main;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement