Как при помощи флажка CheckBox реализовать возможность поиска только положительных корней корней уравнения? - вопрос №2823906

procedure TForm3.Button1Click(Sender: TObject);
Var a,b,c,D,x1,x2:double;

Begin
if Trim(Edit_A.Text)='' then

begin
ShowMessage('введите коэффициенты А');
Edit_A.SetFocus;
Exit;
End;


if Trim(Edit_B.Text)='' then
begin
ShowMessage('введите коэффициенты B');
Edit_B.SetFocus;
Exit;
End;
if Trim(Edit_C.Text)='' then
begin
ShowMessage('введите коэффициенты C');
Edit_C.SetFocus;
Exit;
End;



a:=StrToFloat(Edit_A.Text);
b:=StrToFloat(Edit_B.Text);
c:=StrToFloat(Edit_C.Text);
if a=0 then
if b<>0 then
begin
x1:=-c/b;
x2:=x1;
end
else
begin
ShowMessage('Коэффициенты А и В равны нулю');
exit;
end
else
begin
D:=b*b-4*a*c;
if D<0 then
begin
ShowMessage('Дискриминант отрицателен.');
exit;
end
else
begin
x1:=(-b+sqrt(D))/(2*a);
x2:=(-b-sqrt(D))/(2*a);
end;
end;
x1:=(-b+sqrt(D))/(2*a);
x2:=(-b-sqrt(D))/(2*a);

StringGrid_Result.Cells[0,1]:=FloatToStr(x1);
StringGrid_Result.Cells[1,1]:=FloatToStr(x2);
end;



procedure TForm3.CheckBox1Click(Sender: TObject);
Var b,a,d,x1,x2:double;
begin
if CheckBox1.Checked=true then
begin
x1:=(-b+sqrt(D))/(2*a);
x2:=(-b-sqrt(D))/(2*a);
end;
if x2>0
then
begin
StringGrid_Result.Cells[0,1]:=FloatToStr(x1);
StringGrid_Result.Cells[1,1]:=FloatToStr(x2);
end
else
ShowMessage('..');
end;


procedure TForm3.Edit_AClick(Sender: TObject);
begin
Edit_A.Clear;
end;

procedure TForm3.Edit_AKeyPress(Sender: TObject; var Key: Char);
begin
if (Key in ['0'..'9','-',Chr(44),Chr(VK_BACK)])=false then Key:=#0;
end;



procedure TForm3.Edit_BClick(Sender: TObject);
begin
edit_B.Clear;
end;

procedure TForm3.Edit_CClick(Sender: TObject);
begin
Edit_C.Clear;
end;

procedure TForm3.FormShow(Sender: TObject);
begin
StringGrid_Result.Cells[0,0]:='x1';
StringGrid_Result.Cells[1,0]:='x2';
end;

end.
30.03.18
0 ответов
Ответов пока нет
Посмотреть всех экспертов из раздела Технологии > Delphi
Пользуйтесь нашим приложением Доступно на Google Play Загрузите в App Store