Autor Beitrag
Benni28
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 16.03.09 17:16 
Hallo, ich habe für die Schule ein Programm schreiben müssen, welches die Schnittpunkte einer linearen Funktion und quadratischen Funktion ausgibt und die beiden Graphen in ein Koordinatensystem zeichnet. Leider habe ich bestimmt einige Fehler gemacht, die ich aber nicht heraus finde. Die Schnittpunkte werden nicht berechnet und die lineare Funktion wird auch nicht gezeichnet. Vielleicht sieht ja jemand meine Fehler auf anhieb und kann mir Helfen. Im vorraus schon mal danke.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ExtCtrls;

type
  TForm1 = class(TForm)
    bild: TImage;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Bearbeiten1: TMenuItem;
    Sc1: TMenuItem;
    Schnittpunkteberechnen1: TMenuItem;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Lschen1: TMenuItem;
    Edit4: TEdit;
    Edit5: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Graphzeichnen1: TMenuItem;
    procedure Lschen1Click(Sender: TObject);
    procedure Graphzeichnen1Click(Sender: TObject);
    procedure Sc1Click(Sender: TObject);
    {procedure Schnittpunkteberechnen1Click(Sender: TObject);}
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  function f(x:real):real;
  function g(x:real):real;

var
  Form1: TForm1;
  a,b,c,d,n,m,x,y,x2,y2:real;
  xb,yb,xm,ym,k,ymax,xmax:word;

implementation

{$R *.dfm}

function f(x:real):real;
begin
f:=a*x*x+b*x+c*x
end;

function g(x:real):real;
begin
g:=m*x+n;
end;

procedure diskriminante;
begin
d:=((b-m)*0,5)-(c-n);
end;

procedure loeschen;
begin
with form1.bild.canvas do
begin
brush.color:=clwhite;
pen.color:=clwhite;
rectangle(0,0,form1.bild.width,form1.bild.height);
end;
end;

procedure koordinatensystem;
var i :integer;
begin
k:=30;
xm:=form1.bild.width div 2;
ym:=form1.bild.height div 2;
xmax:=form1.bild.width;
ymax:=form1.bild.height;
with form1.bild.canvas do
begin
moveto (10,ym); lineto (xmax-10,ym);
moveto (xm,10); lineto (xm,ymax-10);
font.name:='Arial';
font.size:=8;
xb:=xm-5*k;
for i:=-5 to 5 do
begin
moveto (xb,ym); lineto (xb,ym+3);
textout (xb-3,ym+5,inttostr(i));
xb:=xb+k;
end;
yb:=ym+5*k;
for i:=-5 to 5 do
begin
moveto (xm,yb);lineto (xm+3,yb);
if i<>0 then textout (xm+5,yb-5,inttostr(i));
yb:=yb-k;
end;
end;
end;

procedure TForm1.Lschen1Click(Sender: TObject);
begin
loeschen;
end;

procedure TForm1.Graphzeichnen1Click(Sender: TObject);
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
c:=strtofloat(edit3.text);
m:=strtofloat(edit4.text);
n:=strtofloat(edit5.text);
koordinatensystem;
x:=-5;
repeat
y:=f(x);
xb:=round(xm+x*k);
yb:=round(ym-y*k);
bild.canvas.pixels[xb,yb]:=clblack;
x:=x+0.001;
until x>5
end;
begin
x:=-5;
repeat
y:=g(x);
xb:=round(xm+x*k);
yb:=round(ym-y*k);
bild.canvas.pixels[xb,yb]:=clblack;
x:=x+0.001;
until x>5
end;


procedure TForm1.Sc1Click(Sender: TObject);
begin
close;
end;

procedure TForm1.Schnittpunkteberechnen1Click(Sender: TObject);
begin
a:=strtofloat(edit1.text);
b:=strtofloat(edit2.text);
c:=strtofloat(edit3.text);
m:=strtofloat(edit4.text);
n:=strtofloat(edit5.text);
begin
if d<0 do
end;
begin
if d=0 do
x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
y:=m*x+n;
edit6.text:=floattostr(x);
edit7.text:=floattostr(y);
end;
begin
if d>0 do
x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
x2:=((-b+m)*0,5)-(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
y:=m*x+n;
y2:=m*x2+n;
edit6.text:=floattostr(x);
edit7.text:=floattostr(y);
edit8.text:=floattostr(x2);
edit9.text:=floattostr(y2);
end;
end;

end.
platzwart
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 1054
Erhaltene Danke: 78

Win 7, Ubuntu 9.10
Delphi 2007 Pro, C++, Qt
BeitragVerfasst: Mo 16.03.09 17:35 
Hallo,

leider ist dein Quelltext überhaupt nicht lesbar. Bitte versehe ihn mit entsprechenden Einrückungen bzw. nur einem Befehl pro Zeile, Danke ;)

_________________
Wissenschaft schafft Wissenschaft, denn Wissenschaft ist Wissenschaft, die mit Wissen und Schaffen Wissen schafft. (myself)
Benni28 Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 16.03.09 17:49 
Ja klar, dass ist machbar. Leider arbeite ich immer so. Ich hoffe so ist es besser.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ExtCtrls;

type
  TForm1 = class(TForm)
    bild: TImage;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Bearbeiten1: TMenuItem;
    Sc1: TMenuItem;
    Schnittpunkteberechnen1: TMenuItem;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Lschen1: TMenuItem;
    Edit4: TEdit;
    Edit5: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Graphzeichnen1: TMenuItem;
    procedure Lschen1Click(Sender: TObject);
    procedure Graphzeichnen1Click(Sender: TObject);
    procedure Sc1Click(Sender: TObject);
    procedure Schnittpunkteberechnen1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  function f(x:real):real;
  function g(x:real):real;

var
  Form1: TForm1;
  a,b,c,d,n,m,x,y,x2,y2:real;
  xb,yb,xm,ym,k,ymax,xmax:word;

implementation

{$R *.dfm}

function f(x:real):real;
begin
 f:=a*x*x+b*x+c*x
end;

function g(x:real):real;
begin
 g:=m*x+n;
end;

procedure diskriminante;
begin
 d:=((b-m)*0,5)-(c-n);
end;

procedure loeschen;
begin
 with form1.bild.canvas do
  begin
   brush.color:=clwhite;
   pen.color:=clwhite;
   rectangle(0,0,form1.bild.width,form1.bild.height);
  end;
end;

procedure koordinatensystem;
var i :integer;
begin
 k:=30;
 xm:=form1.bild.width div 2;
 ym:=form1.bild.height div 2;
 xmax:=form1.bild.width;
 ymax:=form1.bild.height;
 with form1.bild.canvas do
  begin
   moveto (10,ym);
   lineto (xmax-10,ym);
   moveto (xm,10);
   lineto (xm,ymax-10);
   font.name:='Arial';
   font.size:=8;
   xb:=xm-5*k;
   for i:=-5 to 5 do
    begin
    moveto (xb,ym);
    lineto (xb,ym+3);
    textout (xb-3,ym+5,inttostr(i));
    xb:=xb+k;
  end;
 yb:=ym+5*k;
 for i:=-5 to 5 do
     begin
      moveto (xm,yb);lineto (xm+3,yb);
      if i<>0 then textout (xm+5,yb-5,inttostr(i));
      yb:=yb-k;
     end;
 end;
end;

procedure TForm1.Lschen1Click(Sender: TObject);
begin
 loeschen;
end;

procedure TForm1.Graphzeichnen1Click(Sender: TObject);
begin
 a:=strtofloat(edit1.text);
 b:=strtofloat(edit2.text);
 c:=strtofloat(edit3.text);
 m:=strtofloat(edit4.text);
 n:=strtofloat(edit5.text);
 koordinatensystem;
 x:=-5;
 repeat
  y:=f(x);
  xb:=round(xm+x*k);
  yb:=round(ym-y*k);
  bild.canvas.pixels[xb,yb]:=clblack;
  x:=x+0.001;
  until x>5
 end;
  begin
   x:=-5;
   repeat
    y:=g(x);
    xb:=round(xm+x*k);
    yb:=round(ym-y*k);
    bild.canvas.pixels[xb,yb]:=clblack;
    x:=x+0.001;
    until x>5
   end;
end;

procedure TForm1.Sc1Click(Sender: TObject);
begin
 close;
end;

procedure TForm1.Schnittpunkteberechnen1Click(Sender: TObject);
begin
 a:=strtofloat(edit1.text);
 b:=strtofloat(edit2.text);
 c:=strtofloat(edit3.text);
 m:=strtofloat(edit4.text);
 n:=strtofloat(edit5.text);
 begin
  if d<0 do
 end;
  begin
   if d=0 do
   x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
   y:=m*x+n;
   edit6.text:=floattostr(x);
   edit7.text:=floattostr(y);
  end;
   begin
    if d>0 do
    x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    x2:=((-b+m)*0,5)-(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    y:=m*x+n;
    y2:=m*x2+n;
    edit6.text:=floattostr(x);
    edit7.text:=floattostr(y);
    edit8.text:=floattostr(x2);
    edit9.text:=floattostr(y2);
   end;
end;

end.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mo 16.03.09 18:14 
Der Abschnitt ist schonmal falsch. Es heißt if ... then und nicht if ... do. Wenn man es dann richtig einrückt, siehst du, dass das mit dem begin und end gar nicht passt. Das begin muss nach dem if folgen.

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
procedure TForm1.Schnittpunkteberechnen1Click(Sender: TObject);
begin
  a:=strtofloat(edit1.text);
  b:=strtofloat(edit2.text);
  c:=strtofloat(edit3.text);
  m:=strtofloat(edit4.text);
  n:=strtofloat(edit5.text);

  begin
    if d<0 do
  end;

  begin
    if d=0 do
      x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    y:=m*x+n;
    edit6.text:=floattostr(x);
    edit7.text:=floattostr(y);
  end;

  begin
    if d>0 do
      x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    x2:=((-b+m)*0,5)-(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    y:=m*x+n;
    y2:=m*x2+n;
    edit6.text:=floattostr(x);
    edit7.text:=floattostr(y);
    edit8.text:=floattostr(x2);
    edit9.text:=floattostr(y2);
  end;
end;

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Benni28 Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 16.03.09 18:29 
ja und ich müsste d erstmal berechnen lassen, also die prozedur aufrufen
Benni28 Threadstarter
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Mo 16.03.09 18:47 
Sieht dann jetzt so aus:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ExtCtrls;

type
  TForm1 = class(TForm)
    bild: TImage;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Bearbeiten1: TMenuItem;
    Sc1: TMenuItem;
    Schnittpunkteberechnen1: TMenuItem;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Lschen1: TMenuItem;
    Edit4: TEdit;
    Edit5: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Graphzeichnen1: TMenuItem;
    procedure Lschen1Click(Sender: TObject);
    procedure Graphzeichnen1Click(Sender: TObject);
    procedure Sc1Click(Sender: TObject);
    procedure Schnittpunkteberechnen1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  function f(x:real):real;
  function g(x:real):real;

var
  Form1: TForm1;
  a,b,c,d,n,m,x,y,x2,y2:real;
  xb,yb,xm,ym,k,ymax,xmax:word;

implementation

{$R *.dfm}

function f(x:real):real;
begin
 f:=a*x*x+b*x+c*x
end;

function g(x:real):real;
begin
 g:=m*x+n;
end;

procedure diskriminante;
begin
 d:=((b-m)*0,5)-(c-n);
end;

procedure loeschen;
begin
 with form1.bild.canvas do
  begin
   brush.color:=clwhite;
   pen.color:=clwhite;
   rectangle(0,0,form1.bild.width,form1.bild.height);
  end;
end;

procedure koordinatensystem;
var i :integer;
begin
 k:=30;
 xm:=form1.bild.width div 2;
 ym:=form1.bild.height div 2;
 xmax:=form1.bild.width;
 ymax:=form1.bild.height;
 with form1.bild.canvas do
  begin
   moveto (10,ym);
   lineto (xmax-10,ym);
   moveto (xm,10);
   lineto (xm,ymax-10);
   font.name:='Arial';
   font.size:=8;
   xb:=xm-5*k;
   for i:=-5 to 5 do
    begin
    moveto (xb,ym);
    lineto (xb,ym+3);
    textout (xb-3,ym+5,inttostr(i));
    xb:=xb+k;
  end;
 yb:=ym+5*k;
 for i:=-5 to 5 do
     begin
      moveto (xm,yb);lineto (xm+3,yb);
      if i<>0 then textout (xm+5,yb-5,inttostr(i));
      yb:=yb-k;
     end;
 end;
end;

procedure TForm1.Lschen1Click(Sender: TObject);
begin
 loeschen;
end;

procedure TForm1.Graphzeichnen1Click(Sender: TObject);
begin
 a:=strtofloat(edit1.text);
 b:=strtofloat(edit2.text);
 c:=strtofloat(edit3.text);
 m:=strtofloat(edit4.text);
 n:=strtofloat(edit5.text);
 koordinatensystem;
 x:=-5;
 repeat
  y:=f(x);
  xb:=round(xm+x*k);
  yb:=round(ym-y*k);
  bild.canvas.pixels[xb,yb]:=clblack;
  x:=x+0.001;
  until x>5
 end;
  begin
   x:=-5;
   repeat
    y:=g(x);
    xb:=round(xm+x*k);
    yb:=round(ym-y*k);
    bild.canvas.pixels[xb,yb]:=clblack;
    x:=x+0.001;
    until x>5
   end;
end;

procedure TForm1.Sc1Click(Sender: TObject);
begin
 close;
end;

procedure TForm1.Schnittpunkteberechnen1Click(Sender: TObject);
begin
 a:=strtofloat(edit1.text);
 b:=strtofloat(edit2.text);
 c:=strtofloat(edit3.text);
 m:=strtofloat(edit4.text);
 n:=strtofloat(edit5.text);
 diskriminante;
  if d<0 then
  end;
  if d=0 then
   begin
    x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    y:=m*x+n;
    edit6.text:=floattostr(x);
    edit7.text:=floattostr(y);
    end;
  else
   begin
    x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    x2:=((-b+m)*0,5)-(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    y:=m*x+n;
    y2:=m*x2+n;
    edit6.text:=floattostr(x);
    edit7.text:=floattostr(y);
    edit8.text:=floattostr(x2);
    edit9.text:=floattostr(y2);
   end;
end;

end.
Mr_Emre_D
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 114
Erhaltene Danke: 14



BeitragVerfasst: Mo 16.03.09 19:29 
ausblenden Delphi-Quelltext
1:
2:
  if d<0 then
  end;


Ich rate dir ein Delphi-Buch / Online Tutorial zu lesen !

MfG ;)
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Mo 16.03.09 19:41 
user profile iconMr_Emre_D hat folgendes geschrieben Zum zitierten Posting springen:
Ich rate dir ein Delphi-Buch / Online Tutorial zu lesen !

MfG ;)
Wie zum Beispiel den Delphi Crashkurs von Christian S. der wirklich toll und umfangreich ist :zustimm:

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Mo 16.03.09 21:45 
Also dein Quelltext sieht auf jeden Fall sehr lang aus, ich meine, dass es kürzer geht. :wink:

zum Thema "Buch": [url]de.wikibooks.org/wiki/Delphi[/url] - das ist auch ziemlich gut.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 16.03.09 22:04 
Was ich mich frage: Wie kann das sein, dass du die Fehler nicht schon beim Schreiben bemerkt hast? Dass sich diese Konstrukte nicht kompilieren lassen, hättest du doch viel früher merken müssen.

Oder schreibst du den Quelltext herunter und kompilierst und testest zwischendurch nicht?!?

Dein repeat..until hat auch ein end zu viel. Und Groß- und Kleinschreibung kennst du? :roll: Richtig eingerückt sähe der Quelltext so aus:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
procedure TForm1.Graphzeichnen1Click(Sender: TObject);
begin
  a := StrToFloat(Edit1.Text);
  b := StrToFloat(Edit2.Text);
  c := StrToFloat(Edit3.Text);
  m := StrToFloat(Edit4.Text);
  n := StrToFloat(Edit5.Text);
  koordinatensystem;
  x := -5;
  repeat
    y := f(x);
    xb := Round(xm + x * k);
    yb := Round(ym - y * k);
    bild.Canvas.Pixels[xb, yb] := clBlack;
    x := x+0.001;
  until x > 5;
end// damit wäre die Prozedur beendet

begin // neues begin
  x := -5;
  repeat
    y := g(x);
    xb := Round(xm + x * k);
    yb := Round(ym - y * k);
    bild.Canvas.Pixels[xb, yb] := clBlack;
    x := x + 0.001;
  until x > 5;
end// gehört zu dem neuen begin
end;
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Mo 16.03.09 22:33 
Naja, laut StyleGuide ist es erlaubt, ein Semikolon vor einem end; wegzulassen. Und mit dem Einrücken haben auch viele Lehrer Schwierigkeiten. :lol:

edit: Ich rate davon ab, einen Graphen mit Canvas.Pixels[x,y] zu zeichnen. Nimm lieber Linien.


Zuletzt bearbeitet von Jakob_Ullmann am Mo 16.03.09 22:35, insgesamt 1-mal bearbeitet
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19346
Erhaltene Danke: 1754

W11 x64 (Chrome, Edge)
Delphi 12 Pro, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Mo 16.03.09 22:35 
user profile iconJakob_Ullmann hat folgendes geschrieben Zum zitierten Posting springen:
Naja, laut StyleGuide ist es erlaubt, ein Semikolon vor einem end; wegzulassen.
Vor einem end ja, aber hier gehört ja gar keins hin, genausowenig wie bei der seltsamen if-Konstruktion.

user profile iconJakob_Ullmann hat folgendes geschrieben Zum zitierten Posting springen:
Und mit dem Einrücken haben auch viele Lehrer Schwierigkeiten. :lol:
Nicht nur damit... leider...
Jakob_Ullmann
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1747
Erhaltene Danke: 15

Win 7, *Ubuntu GNU/Linux*
*Anjuta* (C, C++, Python), Geany (Vala), Lazarus (Pascal), Eclipse (Java)
BeitragVerfasst: Di 17.03.09 19:58 
Also ich habs mir jetzt mal genauer angesehen

user profile iconBenni28 hat folgendes geschrieben Zum zitierten Posting springen:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Menus, ExtCtrls;

type
  TForm1 = class(TForm)
    bild: TImage;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Bearbeiten1: TMenuItem;
    Sc1: TMenuItem;
    Schnittpunkteberechnen1: TMenuItem;
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Lschen1: TMenuItem;
    Edit4: TEdit;
    Edit5: TEdit;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Graphzeichnen1: TMenuItem;
    procedure Lschen1Click(Sender: TObject);
    procedure Graphzeichnen1Click(Sender: TObject);
    procedure Sc1Click(Sender: TObject);
    procedure Schnittpunkteberechnen1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

  function f(x:real):real;
  function g(x:real):real;

var
  Form1: TForm1;
  a,b,c,d,n,m,x,y,x2,y2:real;
  xb,yb,xm,ym,k,ymax,xmax:word;

implementation

{$R *.dfm}

function f(x:real):real;
begin
 f:=a*x*x+b*x+c*x
end;

function g(x:real):real;
begin
 g:=m*x+n;
end;

procedure diskriminante;
begin
 d:=((b-m)*0,5)-(c-n);
end;

procedure loeschen;
begin
 // form1 zu schreiben ist nicht falsch
 // ich würde es aber als sauberer erachten, einfach
 // die procedure als TForm1.loeschen zu deklarieren, demnach
 // oben auch in den Private-Bereich von TForm1 eintragen
 with form1.bild.canvas do
  begin
   brush.color:=clwhite;
   pen.color:=clwhite;
   rectangle(0,0,form1.bild.width,form1.bild.height);
  end;
  // bitte immer um zwei Leerzeichen einrücken
  // ich empfehle dir:
  // http://www.delphi-treff.de/delphi-styleguide/
end;

procedure koordinatensystem;
// dasselbe...
var i :integer;
begin
 k:=30;
 xm:=form1.bild.width div 2;
 ym:=form1.bild.height div 2;
 xmax:=form1.bild.width;
 ymax:=form1.bild.height;
 with form1.bild.canvas do
  begin
   moveto (10,ym);
   lineto (xmax-10,ym);
   moveto (xm,10);
   lineto (xm,ymax-10);
   font.name:='Arial';
   font.size:=8;
   xb:=xm-5*k;
   for i:=-5 to 5 do
    begin
    moveto (xb,ym);
    lineto (xb,ym+3);
    textout (xb-3,ym+5,inttostr(i));
    xb:=xb+k;
  end;
 yb:=ym+5*k;
 for i:=-5 to 5 do
     begin
      moveto (xm,yb);lineto (xm+3,yb);
      if i<>0 then textout (xm+5,yb-5,inttostr(i));
      yb:=yb-k;
     end;
 end;
end;

procedure TForm1.Lschen1Click(Sender: TObject);
begin
 loeschen;
end;

procedure TForm1.Graphzeichnen1Click(Sender: TObject);
begin
 a:=strtofloat(edit1.text);
 b:=strtofloat(edit2.text);
 c:=strtofloat(edit3.text);
 m:=strtofloat(edit4.text);
 n:=strtofloat(edit5.text);
 { Groß- und Kleinschreibung!!! }
 koordinatensystem;
 x:=-5;
 repeat
  y:=f(x);
  xb:=round(xm+x*k);
  yb:=round(ym-y*k);
  bild.canvas.pixels[xb,yb]:=clblack;
  // wie gesagt, keine Pixels!!
  x:=x+0.001;
  until x>5
 end;
  begin
   x:=-5;
   repeat
    y:=g(x);
    xb:=round(xm+x*k);
    yb:=round(ym-y*k);
    bild.canvas.pixels[xb,yb]:=clblack;
    x:=x+0.001;
    until x>5
   end;
  // überflüssig
end;

procedure TForm1.Sc1Click(Sender: TObject);
begin
 close;
end;

procedure TForm1.Schnittpunkteberechnen1Click(Sender: TObject);
begin
 a:=strtofloat(edit1.text);
 b:=strtofloat(edit2.text);
 c:=strtofloat(edit3.text);
 m:=strtofloat(edit4.text);
 n:=strtofloat(edit5.text);
 diskriminante;
  if d<0 then
  end;
  if d=0 then
   begin
    x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    y:=m*x+n;
    edit6.text:=floattostr(x);
    edit7.text:=floattostr(y);
    end;
  else
   begin
    x:=((-b+m)*0,5)+(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    x2:=((-b+m)*0,5)-(sqr(((b-m)*0,5)*((b-m)*0,5)-(c-n)));
    y:=m*x+n;
    y2:=m*x2+n;
    edit6.text:=floattostr(x);
    edit7.text:=floattostr(y);
    edit8.text:=floattostr(x2);
    edit9.text:=floattostr(y2);
   end;
end;

end.


Zu den Schnittpunkten:

a*x² + b*x + c = d*x² + e*x + f

nach x umstellen: http://latex.univie.ac.at/?x=\frac{\pm%20\sqrt{-4\cdot%20a%20\cdot%20(c-f)+b^2%20-%202%20b%20e%20+%204%20c%20d%20-%204%20d%20f%20+%20e^2}%20-%20b%20+%20e}{2%20\cdot%20(a-d)}