Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Unit Main;
- Interface
- Uses
- Winapi.Windows,
- Winapi.Messages,
- System.SysUtils,
- System.Variants,
- System.Classes,
- Vcl.Graphics,
- Clipbrd,
- Vcl.Controls,
- Vcl.Forms,
- Vcl.Dialogs,
- Vcl.StdCtrls,
- Vcl.Menus,
- Vcl.ExtCtrls,
- Vcl.Imaging.Pngimage;
- Type
- TMainForm = Class(TForm)
- Button1: TButton;
- EditA: TEdit;
- EditB: TEdit;
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- N5: TMenuItem;
- Y1: TLabel;
- X: TLabel;
- BalloonHint1: TBalloonHint;
- OpenDialog1: TOpenDialog;
- SaveDialog1: TSaveDialog;
- Y: TLabel;
- Result: TMemo;
- LabelTask: TLabel;
- ImageTask: TImage;
- EditC: TEdit;
- EditD: TEdit;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Procedure Button1Click(Sender: TObject);
- Procedure N2Click(Sender: TObject);
- Procedure N5Click(Sender: TObject);
- Procedure EditBKeyPress(Sender: TObject; Var Key: Char);
- Procedure EditAKeyPress(Sender: TObject; Var Key: Char);
- Procedure N3Click(Sender: TObject);
- Procedure GetPath(Var Path: String);
- Procedure N4Click(Sender: TObject);
- Procedure Checker(Var IsCorrect: Boolean);
- Procedure N1Click(Sender: TObject);
- Procedure EditAChange(Sender: TObject);
- Procedure EditBChange(Sender: TObject);
- Procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Procedure EditRadMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Procedure EditAMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Procedure EditBMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Procedure FormMouseEnter(Sender: TObject);
- Procedure EditCChange(Sender: TObject);
- Procedure EditCKeyPress(Sender: TObject; Var Key: Char);
- Procedure EditDKeyPress(Sender: TObject; Var Key: Char);
- Procedure EditDChange(Sender: TObject);
- Procedure EditCMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Procedure EditDMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Private
- { Private declarations }
- Public
- { Public declarations }
- End;
- Const
- E: Double = 1.0E-3;
- NumSet = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', #8, #44, #45, #46];
- Var
- MainForm: TMainForm;
- Implementation
- {$R *.dfm}
- Uses
- Instruction,
- Information;
- Procedure TmainForm.Checker(Var IsCorrect: Boolean);
- Begin
- IsCorrect := True;
- Try
- StrtoFloat(EditA.Text);
- Except
- IsCorrect := False;
- End;
- Try
- StrtoFloat(EditB.Text);
- Except
- IsCorrect := False;
- End;
- End;
- Function NOD(A, B: Integer): Integer;
- Var
- Temp: Integer;
- Begin
- While B <> 0 Do
- Begin
- Temp := B;
- B := A Mod B;
- A := Temp;
- End;
- NOD := A;
- End;
- Function CheckNum(A, B: INTEGER): Boolean;
- begin
- Result := Abs(A) < Abs(B);
- end;
- Function ChecSokr(A, B: INTEGER): Boolean;
- begin
- Result := not((NOD(abs(a),abs(b)) <> 1) or ((a<0) and (b<0)));
- end;
- Procedure TMainForm.Button1Click(Sender: TObject);
- Var
- A, B, C, D, NumEnd, DenomEnd, Temp: Integer;
- IsCorrect: Boolean;
- Begin
- A := StrtoInt(EditA.Text);
- B := StrtoInt(EditB.Text);
- C := StrtoInt(EditC.Text);
- D := StrtoInt(EditD.Text);
- Checker(IsCorrect);
- if not (checknum(a,b) and checknum(c,d)) Then
- ShowMessage('Введите обыкновенные дроби.')
- else if not (ChecSokr(A, B) and ChecSokr(c, d)) then
- ShowMessage('Введите несократимые дроби.')
- else If IsCorrect then
- Begin
- A := StrtoInt(EditA.Text);
- B := StrtoInt(EditB.Text);
- C := StrtoInt(EditC.Text);
- D := StrtoInt(EditD.Text);
- DenomEnd := B * D;
- NumEnd := A * D - C * B;
- Temp := NOD(Abs(NumEnd), Abs(DenomEnd));
- NumEnd := NumEnd Div Temp;
- DenomEnd := DenomEnd Div Temp;
- If NumEnd Mod DenomEnd = 0 Then
- Begin
- Result.Lines.Clear;
- Result.Lines.Add('Искомая дробь: ' + IntToStr(NumEnd div DenomEnd));
- End
- Else
- Begin
- Result.Lines.Clear;
- Result.Lines.Add('Искомая дробь: ' + IntToStr(NumEnd) + '/' + IntToStr(DenomEnd));
- End;
- End
- Else
- Begin
- ShowMessage('Заполните все поля');
- End;
- End;
- Procedure TMainForm.EditBChange(Sender: TObject);
- Begin
- EditB.MaxLength := 6;
- If Length(EditB.Text) = 0 Then
- Begin
- Result.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditBKeyPress(Sender: TObject; Var Key: Char);
- begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditB.Text) = 1 Then
- Begin
- If EditB.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditB.Text) = 2 Then
- Begin
- If (EditB.Text[1] = '-') AND (EditB.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditB.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditB);
- Key := #0;
- End;
- End;
- if Key = '0' then // Проверяем знак минус
- begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число неравное 0.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditB);
- Key := #0;
- end;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditB.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditB);
- Key := #0;
- End
- Else
- If Length(EditB.Text) > 0 Then
- Begin
- If (EditB.Text[1] = '-') AND (Length(EditB.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditB.SelStart = 0 Then
- Begin
- EditB.Text := '0' + EditB.Text;
- EditB.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число..';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditB);
- Key := #0;
- End;
- End;
- Procedure TMainForm.EditBMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Begin
- Clipboard.Clear;
- End;
- Procedure TMainForm.EditCChange(Sender: TObject);
- Begin
- EditC.MaxLength := 6;
- If Length(EditC.Text) = 0 Then
- Begin
- Result.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditCKeyPress(Sender: TObject; Var Key: Char);
- Begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditC.Text) = 1 Then
- Begin
- If EditC.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditC.Text) = 2 Then
- Begin
- If (EditC.Text[1] = '-') AND (EditC.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditC.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditC);
- Key := #0;
- End;
- End;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditC.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditC);
- Key := #0;
- End
- Else
- If Length(EditC.Text) > 0 Then
- Begin
- If (EditC.Text[1] = '-') AND (Length(EditC.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditC.SelStart = 0 Then
- Begin
- EditC.Text := '0' + EditB.Text;
- EditC.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число..';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditC);
- Key := #0;
- End;
- End;
- Procedure TMainForm.EditCMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Begin
- Clipboard.Clear;
- End;
- Procedure TMainForm.EditDChange(Sender: TObject);
- Begin
- EditD.MaxLength := 6;
- If Length(EditD.Text) = 0 Then
- Begin
- Result.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditDKeyPress(Sender: TObject; Var Key: Char);
- Begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditD.Text) = 1 Then
- Begin
- If EditD.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditD.Text) = 2 Then
- Begin
- If (EditD.Text[1] = '-') AND (EditD.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditD.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditD);
- Key := #0;
- End;
- End;
- if Key = '0' then // Проверяем знак минус
- begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число неравное 0.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditD);
- Key := #0;
- end;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditD.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditD);
- Key := #0;
- End
- Else
- If Length(EditD.Text) > 0 Then
- Begin
- If (EditD.Text[1] = '-') AND (Length(EditD.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditD.SelStart = 0 Then
- Begin
- EditD.Text := '0' + EditD.Text;
- EditD.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число..';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditD);
- Key := #0;
- End;
- End;
- Procedure TMainForm.EditDMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Begin
- Clipboard.Clear;
- End;
- Procedure TMainForm.EditRadMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Begin
- Clipboard.Clear;
- End;
- Procedure TMainForm.FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
- Var
- Confirmation: Integer;
- Begin
- Confirmation := Application.MessageBox('Вы действительно хотите выйти?', 'Выход', MB_YESNO);
- CanClose := Confirmation = IDYES;
- End;
- Procedure TMainForm.FormMouseEnter(Sender: TObject);
- Begin
- Clipboard.Clear;
- End;
- Procedure TMainForm.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Begin
- If (EditA.Text <> '') And (EditB.Text <> '') Then
- Button1.Enabled := True
- Else
- Button1.Enabled := False;
- End;
- Procedure TMainForm.EditAChange(Sender: TObject);
- Begin
- EditA.MaxLength := 6;
- If Length(EditA.Text) = 0 Then
- Begin
- Result.Lines.Clear;
- End;
- End;
- Procedure TMainForm.EditAKeyPress(Sender: TObject; Var Key: Char);
- Begin
- If Key In NumSet Then
- Begin
- If Key = '0' Then
- Begin
- If Length(EditA.Text) = 1 Then
- Begin
- If EditA.Text[1] In ['0'] Then
- Begin
- Key := #0;
- End;
- End;
- If Length(EditA.Text) = 2 Then
- Begin
- If (EditA.Text[1] = '-') AND (EditA.Text[2] = '0') Then
- Begin
- Key := #0;
- End;
- End;
- End;
- If Key = #45 Then
- Begin
- If Length(EditA.Text) > 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditA);
- Key := #0;
- End;
- End;
- If Key In [',', '.'] Then
- Begin
- Key := FormatSettings.DecimalSeparator;
- If Pos(Key, EditA.Text) <> 0 Then
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число..';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditA);
- Key := #0;
- End
- Else
- If Length(EditA.Text) > 0 Then
- Begin
- If (EditA.Text[1] = '-') AND (Length(EditA.Text) = 1) Then
- Begin
- Key := #0;
- End
- End
- Else
- If EditA.SelStart = 0 Then
- Begin
- EditA.Text := '0' + EditA.Text;
- EditA.SelStart := 1;
- End;
- End;
- End
- Else
- Begin
- BalloonHint1.Title := 'Недопустимый символ.';
- BalloonHint1.Description := 'Здесь можно ввести только число.';
- BalloonHint1.ImageIndex := 1;
- BalloonHint1.ShowHint(EditA);
- Key := #0;
- End;
- End;
- Procedure TMainForm.EditAMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
- Begin
- Clipboard.Clear;
- End;
- Procedure TMainForm.N1Click(Sender: TObject);
- Begin
- If Result.Lines.Count = 0 Then
- Begin
- N4.Enabled := False;
- End
- Else
- Begin
- N4.Enabled := True;
- End;
- End;
- Procedure TMainForm.N2Click(Sender: TObject);
- Begin
- InstructionForm.ShowModal;
- End;
- Procedure TMainForm.GetPath(Var Path: String);
- Begin
- If OpenDialog1.Execute Then
- Begin
- Path := OpenDialog1.FileName;
- End
- Else
- Begin
- ShowMessage('Открытие файла отменено!');
- End;
- End;
- Procedure TMainForm.N3Click(Sender: TObject);
- Var
- IsCorrect, Fail: Boolean;
- Path, Errors, A, B, C, D, Str: String;
- Count: Integer;
- FileElem: TextFile;
- Begin
- GetPath(Path);
- AssignFile(FileElem, Path);
- Fail := False;
- IsCorrect := True;
- Count := 0;
- If Not FileExists(Path) Then
- Begin
- ShowMessage('Файл не найден!');
- Exit;
- End;
- Try
- Try
- Reset(FileElem);
- Except
- CloseFile(FileElem);
- IsCorrect := False;
- ShowMessage('Ошибка открытия файла');
- End;
- If IsCorrect Then
- Begin
- While Not Eof(FileElem) Do
- Begin
- ReadLn(FileElem, Str);
- Inc(Count);
- End;
- CloseFile(FileElem);
- If Count <> 4 Then
- Fail := True;
- End;
- If IsCorrect Then
- Begin
- Reset(FileElem);
- Try
- Readln(FileElem, A);
- StrToInt(A);
- Except
- Fail := True;
- End;
- Try
- Readln(FileElem, B);
- StrToInt(B);
- Except
- Fail := True;
- End;
- Try
- Readln(FileElem, C);
- StrToInt(C);
- Except
- Fail := True;
- End;
- Try
- Readln(FileElem, D);
- StrToInt(D);
- Except
- Fail := True;
- End;
- End;
- Finally
- CloseFile(FileElem);
- ShowMessage('Обработка завершена');
- End;
- If Fail = False Then
- Begin
- If ((-99 > StrToFloat(A)) Or (StrToFloat(A) > 999)) Or ((-99 > StrToFloat(B)) Or (StrToFloat(B) > 999)) Then
- Fail := True;
- End;
- Errors := 'Проверьте введенные данные и повторите попытку!';
- If Fail = True Then
- Begin
- ShowMessage(Errors);
- End
- Else
- Begin
- EditA.Text := A;
- EditB.Text := B;
- EditC.Text := C;
- EditD.Text := D;
- End;
- End;
- Procedure TMainForm.N4Click(Sender: TObject);
- Begin
- If SaveDialog1.Execute Then
- Begin
- Result.Lines.SaveToFile(SaveDialog1.FileName);
- End
- Else
- Begin
- ShowMessage('Сохранение в файл отменено.');
- End;
- End;
- Procedure TMainForm.N5Click(Sender: TObject);
- Begin
- InformationForm.ShowModal;
- End;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement