unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,StrUtils;
type
TForm1 =
class(TForm)
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
term :
string;
positioncounter, counter,I : integer;
position :
array of integer;
summanden :
array of real;
summe : real;
begin
term:=Edit1.Text;
SetLength(position,1);
counter:=0;
if Pos('
+',term) <> 0
then
begin
position[counter]:=Pos('
+',term);
positioncounter:=position[counter];
while PosEx('
+',term,positioncounter+1)<>0
do
begin
counter:=counter+1;
SetLength(position,counter+1);
position[counter]:=PosEx('
+',term,positioncounter+1);
positioncounter:=position[counter];
end;
SetLength(Summanden,counter+1);
Summanden[0]:= strtoint(copy(term,1,Position[0]-1));
for I := 1
to counter -1
do
begin
Summanden[I]:= strtoint(copy(term,Position[I]+1,(Position[I+1]-Position[I]-1)));
end;
summe:=0;
for I := 0
to counter
do
begin
summe:=summe+summanden[I];
end;
Label1.Caption:=FloatToStr(summe);
end;
end;
end.
// Der zweite und der letze Summand werden bei der Addition nicht einbezogen.