Troche algebry :-)

0

Mam problem w delphi :-) Chce żeby mi policzyło wartość z wyrażenia algebraicznego np 25+10/(5+510^) i nie wiem jak to zrobić :( POMOCY ! :-)

0

pregusia napisał:
Mam problem w delphi :-) Chce żeby mi policzyło wartość z wyrażenia algebraicznego np 25+10/(5+510) i nie wiem jak to zrobić :( POMOCY ! :-)

  1. a co to jest 10</sup>

  2. czy chcesz po prostu obliczyc wynik tego co powyzej, czy zrobic analize i wyliczenie wyniku ze stringa '25+10/(5+510^)'?--Pawel {Delphi6 }

Po pierwsze: naciśnij F1

0

Kiedys wspolnymi silami z RFL napisalismy unita co takie rzeczy liczy [tzn ja zaczalem a RFL dokonczyl :)] jak znajde to sie podziele.--sys:&gt logout....

0

Sheitar napisał:
Kiedys wspolnymi silami z RFL napisalismy unita co takie rzeczy liczy [tzn ja zaczalem a RFL dokonczyl :)] jak znajde to sie podziele.
&gt

ze mną tesh możez sie podzielić ... :D--Spin
Delphi - Lets make Windows better....

0

Ma po prostu liczyć wartość, ze stringa :-)

0

Rozmuiem ze dzialanie ma taka forme?

25+10/(5+510)

Wiec jesli tak to funkcja ktora posiadam wyliczyla ze jest to 10,1818181818182, teraz sprawdzmy

25+10/(5+510)
10+10/(5+50)
10+10/(55)
10+0,18181818181818181818181818181818 &lt-wynik dzielenia z kalkulatora MS
10,18181818181818181818181818181818 &lt- yhmmm wynik sie chyba zgadza :)

--sys:&gt logout....

0

{glowa} ale ze mnie egoista. Oto funkcja kotra to potrafi policzyc [zreszta nie tylko to inne rzeczy tez]. Uwaga bo bedzie dlugie ;)

function Policz(CoMaLiczyc: String): String;
var
s, ss, dz, dzs, wynik: String;
zaw1, zaw2, z1, z2, num, num2, znak: Integer;
l1, l2: Real;

procedure liczby;
begin
z1:=znak;
repeat
z1:=z1-1;
until ((dz[z1]&lt&gt'0')and(dz[z1]&lt&gt'1')and(dz[z1]&lt&gt'2')and(dz[z1]&lt&gt'3')and
(dz[z1]&lt&gt'4')and(dz[z1]&lt&gt'5')and(dz[z1]&lt&gt'6')and(dz[z1]&lt&gt'7')and
(dz[z1]&lt&gt'8')and(dz[z1]&lt&gt'9')and(dz[z1]&lt&gt','))or(z1=1);
if z1&gt1 then z1:=z1+1;
if z1&gt1 then
if dz[z1-1]='-' then
if z1-1=1 then z1:=z1-1 else
if (dz[z1-2]='(')or(dz[z1-2]='-')or(dz[z1-2]='+')or(dz[z1-2]='/')or
(dz[z1-2]='*') then z1:=z1-1;
z2:=znak;
repeat
z2:=z2+1;
if (z2=znak+1)and(dz[znak+1]='-')then z2:=z2+1;
until ((dz[z2]&lt&gt'0')and(dz[z2]&lt&gt'1')and(dz[z2]&lt&gt'2')and(dz[z2]&lt&gt'3')and
(dz[z2]&lt&gt'4')and(dz[z2]&lt&gt'5')and(dz[z2]&lt&gt'6')and(dz[z2]&lt&gt'7')and
(dz[z2]&lt&gt'8')and(dz[z2]&lt&gt'9')and(dz[z2]&lt&gt','))or(z2=length(dz));
if z2&ltlength(dz)then z2:=z2-1;
wynik:=; num:=z1-1; repeat num:=num+1; wynik:=wynik+dz[num]; until num=znak-1; l1:=strtofloat(wynik); wynik:=;
num:=znak;
repeat
num:=num+1;
wynik:=wynik+dz[num];
until num=z2;
l2:=strtofloat(wynik);
end;

procedure dodawanie;
begin
liczby;
num2:=0;
wynik:=`;
repeat
num2:=num2+1;
if (num2&ltz1)or(num2&gtz2)then wynik:=wynik+dz[num2] else
if num2=z1 then wynik:=wynik+floattostr(l1+l2);
until num2=length(dz);
dz:=wynik;
end;

procedure odejmowanie;
begin
liczby;
num2:=0;
wynik:=`;
repeat
num2:=num2+1;
if (num2&ltz1)or(num2&gtz2)then wynik:=wynik+dz[num2] else
if num2=z1 then wynik:=wynik+floattostr(l1-l2);
until num2=length(dz);
dz:=wynik;
end;

procedure mnozenie;
begin
liczby;
num2:=0;
wynik:=`;
repeat
num2:=num2+1;
if (num2&ltz1)or(num2&gtz2)then wynik:=wynik+dz[num2] else
if num2=z1 then wynik:=wynik+floattostr(l1*l2);
until num2=length(dz);
dz:=wynik;
end;

procedure dzielenie;
begin
liczby;
num2:=0;
wynik:=`;
repeat
num2:=num2+1;
if (num2&ltz1)or(num2&gtz2)then wynik:=wynik+dz[num2] else
if num2=z1 then wynik:=wynik+floattostr(l1/l2);
until num2=length(dz);
dz:=wynik;
end;

procedure potegowanie;
begin
liczby;
num2:=0;
wynik:='';
repeat
num2:=num2+1;
if (num2&ltz1)or(num2&gtz2)then wynik:=wynik+dz[num2] else
if num2=z1 then wynik:=wynik+floattostr(power(l1,l2));
until num2=length(dz);
dz:=wynik;
end;

procedure dzialanie;
begin
repeat
num:=0;
dzs:=dz;
repeat
num:=num+1;
until (dz[num]='')or(num=length(dz));
znak:=num;
if dz[num]='
' then potegowanie else
until num=length(dzs);
repeat
num:=0;
dzs:=dz;
repeat
num:=num+1;
until (dz[num]='')or(dz[num]='/')or(num=length(dz));
znak:=num;
if dz[num]='
' then mnozenie else
if dz[num]='/' then dzielenie;
until num=length(dzs);
repeat
num:=0;
dzs:=dz;
repeat
num:=num+1;
until (((dz[num]='+')or(dz[num]='-'))and((num&gt1)and(dz[num-1]&lt&gt'(')and
(dz[num-1]&lt&gt'*')and(dz[num-1]&lt&gt'/')and(dz[num-1]&lt&gt'+')and
(dz[num
-1]&lt&gt'-')))or(num=length(dz));
znak:=num;
if dz[num]='+' then dodawanie else
if dz[num]='-' then odejmowanie;
until num=length(dzs);
end;

begin
s:=CoMaLiczyc;
repeat
num:=0;
zaw2:=0;
zaw1:=0;
repeat
num:=num+1;
if s[num]='(' then zaw1:=num;
if s[num]=')' then zaw2:=num;
until (s[num]=')')or(num=length(s));
ss:=s;
if s[zaw2]=')' then
begin
dz:=; num:=zaw1; repeat num:=num+1; dz:=dz+s[num]; until num=zaw2-1; dzialanie; wynik:=;
num:=0;
repeat
num:=num+1;
if (num&ltzaw1)or(num&gtzaw2)then wynik:=wynik+s[num]else
if num=zaw1 then wynik:=wynik+dz;
until num=length(s);
s:=wynik;
end;
until ss[zaw2]&lt&gt')';
dz:=s;
dzialanie;
s:=dz;
policz:=s;
end;

Autorzy funkcji: Sheitar zaczal, RFL dokonczyl [za co mu BIG {browar} ] :)
--sys:&gt logout....

0

Spoko funkcja!! &gt&gt {hello} Właśnie podobnej szykam!!

Dlaczego ona zwraca wynik jako string a nie jako np cardinal??

Tylko przydały by się jeszcze sin cos tg (ctg) lg ln mod xor and or = &gt &lt =&gt =&lt i jakieś operatory logiczne np jak w Jscripcie: ({boolean})?{jesli true to...}:{to jesli fase}

Ps: Spróbuję zrobić taką która będzie to potrafiła!! :-) --Sebo +)
(Delphi3)

0

Dzięki wam wszystkim ! :-)

0

Hm... troche to zmodyfikowałem :
function Policz(CoMaLiczyc: string): string;
var
s, ss, dz, dzs, wynik: string;
zaw1, zaw2, z1, z2, num, num2, znak, i: Integer;
l1, l2: Extended;

procedure liczby(len:byte);
var I,L:Integer;
W:String;
begin
for I:=znak-1 downto 1 do
begin
if not (dz[I] in znaki) or (I = 1) then break;
end;
z1:=I;

if z1&gt1 then z1:=z1+1;
if z1&gt1 then
if dz[z1-1]='-' then
if z1-1=1 then z1:=z1-1 else
if (dz[z1-2]='(')or(dz[z1-2]='-')or(dz[z1-2]='+')or(dz[z1-2]='/')or
(dz[z1-2]='*') then z1:=z1-1;

L:=0;
for I:=znak+len to length(dz) do
begin
if (I = znak+1) and (dz[znak+1] = '-') then L:=2;
if not (dz[I] in znaki) then break;
end;
z2:=I+L;
if z2&ltlength(dz)then z2:=z2-1;

l1:=StrTofLoat(Copy(dz,z1,znak-z1));
l2:=strtofloat(Copy(dz,znak+len,z2-znak));
end;

procedure funkcja(z:char);
var D,I:Integer;
W:String;
begin
if z = 't' then D:=2 else D:=3;

W:=`;for I:=znak+D to length(dz) do if (dz[I] in znaki) then W:=W+dz[I] else Break;
l1:=StrToFloat(W);
z1:=znak;z2:=I-1;
end;

function power(a,b:Extended):Extended;
var I:integer;
W:Extended;
begin
W:=1;
for i:=1 to round(b) do W:=W*a;
Result:=W;
end;

procedure wykonaj(z:char;l:byte);
var W:Extended;
begin
if l = 1 then
begin
liczby(1);
case z of
'+'=l1+l2;
'-'=l1-l2;
''=l1l2;
'/'=l1/l2;
'^'=power(l1,l2);
end;
end;
if l = 2 then
begin
funkcja(z);
if z = 'c' then W:=cos((3.14l1)/180);
if z = 's' then W:=sin((3.14
l1)/180);
if z = 't' then W:=tan((3.14*l1)/180);
end;
dz:=Copy(dz,1,z1-1) + FloatToStr(W) + Copy(dz,z2+1,length(dz));
end;

procedure dzialanie;
var I,J:Integer;
begin
for I:=1 to length(dz) do
begin
if (dz[I] = 'c') and (dz[I + 1] = 'o') and (dz[I + 2] = 's') then
begin
znak:=I;dzs:=dz;
wykonaj('c',2);
end;
if (dz[I] = 's') and (dz[I + 1] = 'i') and (dz[I + 2] = 'n') then
begin
znak:=I;dzs:=dz;
wykonaj('s',2);
end;
if (dz[I] = 't') and (dz[I + 1] = 'g') then
begin
znak:=I;dzs:=dz;
wykonaj('t',2);
end;

end;

for I:=1 to length(dz) do
begin
if dz[I] = '^' then
begin
znak:=I;dzs:=dz;
wykonaj('^',1);
end;
end;

for I:=1 to length(dz) do
begin
if dz[I] = '' then
begin
znak:=I;dzs:=dz;
wykonaj('
',1);
end;
if dz[I] = '/' then
begin
znak:=I;dzs:=dz;
wykonaj('/',1);
end;
end;

for I:=1 to length(dz) do
begin
if (dz[I] = '+') and ((I &gt 1) and not (dz[I - 1] in ['+','-','','/','('])) then
begin
znak:=I;dzs:=dz;
wykonaj('+',1);
end;
if (dz[I] = '-') and ((I &gt 1) and not (dz[I - 1] in ['+','-','
','/','('])) then
begin
znak:=I;dzs:=dz;
wykonaj('-',1);
end;
end;
end;

begin
s:=CoMaLiczyc;
repeat
num:=0;
zaw2:=0;
zaw1:=0;

for i:=1 to length(s) do
begin
if S[I] = '(' then zaw1:=I;
if S[I] = ')' then begin zaw2:=I;break; end;
end;

ss:=s;
if s[zaw2]=')' then
begin
dz:=Copy(s,zaw1+1,zaw2-zaw1-1);
dzialanie;
wynik:=`;
num:=0;
repeat
num:=num+1;
if (num&ltzaw1)or(num&gtzaw2)then wynik:=wynik+s[num]else
if num=zaw1 then wynik:=wynik+dz;
until num=length(s);
s:=wynik;
end;
until ss[zaw2]&lt&gt')';
dz:=s;
dzialanie;
s:=dz;
policz:=s;
end;

0

Sebo napisał:
&gtTylko przydały by się jeszcze sin cos tg (ctg) lg ln mod xor and or = &gt &lt =&gt =&lt i jakieś operatory logiczne np jak w Jscripcie: ({boolean})?{jesli true to...}:{to jesli fase}

To ja poproszę jeszcze tylko o różniczkowanie i całkowanie :D
To już będzie z tego porządny kalkulator. (A jak się trochę zmodyfikuje to już w szkole uczniowie nie będą musieli robić przebiegu zmienności funkcji)--Jest jeszcze jeden błąd ... :)

0

Sebo napisał:
Spoko funkcja!! &gt&gt {hello} Właśnie podobnej szykam!!
&gt
&gtDlaczego ona zwraca wynik jako string a nie jako np cardinal??
&gt
&gtTylko przydały by się jeszcze sin cos tg (ctg) lg ln mod xor and or = &gt &lt =&gt =&lt i jakieś operatory logiczne np jak w Jscripcie: ({boolean})?{jesli true to...}:{to jesli fase}

do jasnej cholery napisz ją i nie narzekaj, jak ktoś coąś za darmo na forum wrzuca--Spin
Delphi - Lets make Windows better....

1 użytkowników online, w tym zalogowanych: 0, gości: 1