Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit MainForm;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ToolWin;
- type
- TForm1 = class(TForm)
- ToolBar: TToolBar;
- ToolButtonAbout: TToolButton;
- ToolButtonOpen: TToolButton;
- ToolButtonSave: TToolButton;
- EditOfLine: TEdit;
- LabelInf1: TLabel;
- ButtonCalculate: TButton;
- LabelInf2: TLabel;
- LabelInf3: TLabel;
- OpenDialog: TOpenDialog;
- LabelOfVowels: TLabel;
- LabelOfConsonants: TLabel;
- SaveDialog: TSaveDialog;
- procedure ToolButtonAboutClick(Sender: TObject);
- procedure ToolButtonOpenClick(Sender: TObject);
- procedure ButtonCalculateClick(Sender: TObject);
- function CalculateVowels(Line: string): Integer;
- function CalculateConsonants(Line: string): Integer;
- procedure ToolButtonSaveClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- procedure TForm1.ButtonCalculateClick(Sender: TObject);
- var
- Line: string;
- begin
- Line := EditOfLine.Text;
- if Length(Line) <> 0 then
- begin
- LabelOfVowels.Caption := IntToStr(CalculateVowels(Line));
- LabelOfConsonants.Caption := IntToStr(CalculateConsonants(Line));
- end
- else
- MessageDlg('Enter the line!', mtError, [mbOK], 0);
- end;
- function TForm1.CalculateVowels(Line: string): Integer;
- const
- VOWELS_LETTERS = ['а','о','у','ы','э','я','ё','ю','и','е'];
- var
- Amount, I: Integer;
- begin
- Amount := 0;
- Line := AnsiLowerCase(Line);
- for I := 1 to Length(Line) do
- begin
- if AnsiString(Line)[i] in VOWELS_LETTERS then
- Amount := Amount + 1;
- end;
- CalculateVowels := Amount;
- end;
- function TForm1.CalculateConsonants(Line: string): Integer;
- const
- CONSONANTS_LETTERS = ['б','в','г','д','ж','з','й','к','л','м','н','п','р','с','т','ф','х','ц','ч','ш','щ'];
- var
- Amount, I: Integer;
- Consonants: set of char;
- begin
- Amount := 0;
- Line := AnsiLowerCase(Line);
- for I := 1 to High(Line) do
- begin
- if AnsiString(Line)[i] in CONSONANTS_LETTERS then
- Inc(Amount);
- end;
- CalculateConsonants := Amount;
- end;
- procedure TForm1.ToolButtonAboutClick(Sender: TObject);
- begin
- MessageDlg('The program describes the set of vowels and consonants of the Russian language,' +
- 'and determines the number of vowels and consonants' +
- 'in a sentence entered from the keyboard.', mtInformation, [mbOK], 0);
- end;
- procedure TForm1.ToolButtonOpenClick(Sender: TObject);
- var
- InputFile: TextFile;
- IsCorrect: Boolean;
- Line: string;
- begin
- if OpenDialog.Execute then
- begin
- AssignFile(InputFile,OpenDialog.FileName);
- Reset(InputFile);
- if not EOF(InputFile) then
- begin
- Readln(InputFile, Line);
- if not SeekEOF(InputFile) then
- MessageDlg('Part of the file was not read. The program only reads the first line!', mtWarning, [mbOK], 0);
- end
- else
- MessageDlg('File is empty', mtError, [mbOK], 0);
- CloseFile(InputFile);
- end;
- EditOfLine.Text := Line;
- end;
- procedure TForm1.ToolButtonSaveClick(Sender: TObject);
- var
- OutputFile: TextFile;
- begin
- if SaveDialog.Execute then
- begin
- try
- AssignFile(OutputFile, SaveDialog.FileName);
- Rewrite(OutputFile);
- Writeln(OutputFile, 'Vowels: ', LabelOfVowels.Caption);
- Writeln(OutputFile, 'Consonants: ', LabelOfConsonants.Caption);
- CloseFile(OutputFile);
- except
- MessageDlg('Acces error!', mtError, [mbOK], 0);
- end;
- end
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement