Hi!
Hier mal ein kleines Programm zur Berechnung von Quadratischen Gleichungen. Mit diesem Programm werden die Nullstellen, sowie der Scheitelpunkt der Parabeln ausgerechnet, ausserdem wird eine Skizze des Graphen gezeichnet.
[code:1]var
Form1: TForm1;
a:real;
b:real;
c:real;
d:real;
x1:real;
x2:real;
ok:boolean;
k:integer;
x,xk2,y,yk2,sx,sy,p,q:integer;
implementation
{$R *.dfm}
procedure TForm1.berechnungClick(Sender: TObject);
begin
a:=strtofloat(edtax.text);
b:=strtofloat(edtbx.text);
c:=strtofloat(edtc.text);
canvas.MoveTo(350,250);
canvas.LineTo(350,550);
canvas.moveto(150,400);
canvas.lineto(550,400);
if a=0 then
begin
for k:=-20 to 19 do
begin
x:=k*10+350;
xk2:=(k+1)*10+350;
y:=-((round(b)*k))+400-(round(c)*10);
yk2:=-((round(b)*(k+1)))+400-(round(c)*10);
x1:=(-c)/b;
edtx1.text:=floattostr(x1);
edtx2.text:='---';
edtscheitel.text:='---';
if (yk2>=250) and (yk2<=550) and (y>=250) and (y<=550) then
begin
canvas.moveto(x,y);
canvas.LineTo(xk2,yk2);
end;
end;
end;
if a<>0 then
begin
d:=b*b-4*a*c;
if d>0 then
begin
x1:=(-b+(sqrt(b*b-4*a*c)))/(2*a);
x2:=(-b-(sqrt(b*b-4*a*c)))/(2*a);
end;
if d=0 then x1:=(-b)/(2*a);
if d<0 then
begin
edtx1.text:='---';
edtx2.text:='---';
end;
edtx1.text:=floattostr(x1);
edtx2.text:=floattostr(x2);
edtscheitel.text:='('+ floattostr((-b)/(2*a))+'|'+floattostr(c-((b*b)/(4*a)))+')';
for k:=-4 to 3 do
begin
sx:=round(((-b)/(2*a)))*10;
sy:=round(c-((b*b)/(4*a)))*10;
y:=-(round(a)*((k*k)*10))+400-sy;
x:=k*10+350+sx;
yk2:=-(round(a)*(((k+1)*(k+1))*10))+400-sy;
xk2:=(k+1)*10+350+sx;
if (yk2>=250) and (yk2<=550) and (y>=250) and (y<=550) then
begin
canvas.moveto(x,y);
canvas.LineTo(xk2,yk2);
end;
end;
end;
end;
procedure TForm1.restartClick(Sender: TObject);
begin
WinExec(pChar(ParamStr(0)),SW_SHOW);
Close;
end;
end.[/code:1]
Hier mal ein kleines Programm zur Berechnung von Quadratischen Gleichungen. Mit diesem Programm werden die Nullstellen, sowie der Scheitelpunkt der Parabeln ausgerechnet, ausserdem wird eine Skizze des Graphen gezeichnet.
[code:1]var
Form1: TForm1;
a:real;
b:real;
c:real;
d:real;
x1:real;
x2:real;
ok:boolean;
k:integer;
x,xk2,y,yk2,sx,sy,p,q:integer;
implementation
{$R *.dfm}
procedure TForm1.berechnungClick(Sender: TObject);
begin
a:=strtofloat(edtax.text);
b:=strtofloat(edtbx.text);
c:=strtofloat(edtc.text);
canvas.MoveTo(350,250);
canvas.LineTo(350,550);
canvas.moveto(150,400);
canvas.lineto(550,400);
if a=0 then
begin
for k:=-20 to 19 do
begin
x:=k*10+350;
xk2:=(k+1)*10+350;
y:=-((round(b)*k))+400-(round(c)*10);
yk2:=-((round(b)*(k+1)))+400-(round(c)*10);
x1:=(-c)/b;
edtx1.text:=floattostr(x1);
edtx2.text:='---';
edtscheitel.text:='---';
if (yk2>=250) and (yk2<=550) and (y>=250) and (y<=550) then
begin
canvas.moveto(x,y);
canvas.LineTo(xk2,yk2);
end;
end;
end;
if a<>0 then
begin
d:=b*b-4*a*c;
if d>0 then
begin
x1:=(-b+(sqrt(b*b-4*a*c)))/(2*a);
x2:=(-b-(sqrt(b*b-4*a*c)))/(2*a);
end;
if d=0 then x1:=(-b)/(2*a);
if d<0 then
begin
edtx1.text:='---';
edtx2.text:='---';
end;
edtx1.text:=floattostr(x1);
edtx2.text:=floattostr(x2);
edtscheitel.text:='('+ floattostr((-b)/(2*a))+'|'+floattostr(c-((b*b)/(4*a)))+')';
for k:=-4 to 3 do
begin
sx:=round(((-b)/(2*a)))*10;
sy:=round(c-((b*b)/(4*a)))*10;
y:=-(round(a)*((k*k)*10))+400-sy;
x:=k*10+350+sx;
yk2:=-(round(a)*(((k+1)*(k+1))*10))+400-sy;
xk2:=(k+1)*10+350+sx;
if (yk2>=250) and (yk2<=550) and (y>=250) and (y<=550) then
begin
canvas.moveto(x,y);
canvas.LineTo(xk2,yk2);
end;
end;
end;
end;
procedure TForm1.restartClick(Sender: TObject);
begin
WinExec(pChar(ParamStr(0)),SW_SHOW);
Close;
end;
end.[/code:1]