delphi - case..of with function -


this program... need how can use function calkanadmiar 2: in (case rgmetoda.itemindex of) , function calkaniedomiar 3:

unit unit1;  interface  uses   windows, messages, sysutils, variants, classes, graphics, controls, forms,   dialogs, stdctrls, extctrls;  type   fx= function(x:extended):extended;   tform1 = class(tform)     naglowek: tlabel;     label1: tlabel;     label2: tlabel;     label3: tlabel;     label4: tlabel;     label5: tlabel;     label6: tlabel;     label7: tlabel;     edprzedzialy: tedit;     edod: tedit;     eddo: tedit;     pnwynik: tpanel;     oblicz: tbutton;     rgmetoda: tradiogroup;     rb1: tradiobutton;     rb2: tradiobutton;     rb3: tradiobutton;      function f1(x: extended): extended;     function f2(x: extended): extended;     function f3(x: extended): extended;     procedure obliczclick(sender: tobject);     procedure edprzedzialyexit(sender: tobject);     procedure edodexit(sender: tobject);     procedure eddoexit(sender: tobject);       private          function calkanadmiar (odx,dox:extended; n:integer; f:fx):extended;      function calkaniedomiar (odx,dox:extended; n:integer; f:fx):extended;      function calka (odx,dox:extended; n:integer; f:fx):extended;   public     { public declarations }   end;  var   form1: tform1;  implementation  {$r *.dfm}  function tform1.f1(x: extended): extended; begin  result:=sqr(x)+ 2; end;  function tform1.f2(x: extended): extended; begin  result:=3*x - 8; end;  function tform1.f3(x: extended): extended; begin  result:=sin(x) + pi; end;    procedure tform1.obliczclick(sender: tobject); var wynik, h, xi: real;     i,n: word; //h - krok całkowania // wynik - chwilowy lub końcowy wynik danej funkcji //xi - x dla kolejnego kroku całkowania //n - liczba przedziałów //i - obsluga pętli begin  n:=strtoint(edprzedzialy.text);  h:=(strtofloat(eddo.text)-strtofloat(edod.text))/n;  wynik:=0;  case rgmetoda.itemindex of   0: begin //obsługa metody prostok±tów z nadmiarem    if rb1.checked     begin      i:=0 n-1       begin        xi:=strtofloat(edod.text)+i*h;        wynik:= wynik + f1(xi)*h;       end;      pnwynik.caption:= floattostr(wynik);     end;    if rb2.checked     begin      i:=0 n-1       begin        xi:=strtofloat(edod.text)+i*h;        wynik:= wynik + f2(xi)*h;        end;         pnwynik.caption:= floattostr(wynik);       end;     if rb3.checked       begin        i:=0 n-1         begin          xi:=strtofloat(edod.text)+i*h;          wynik:= wynik + f3(xi)*h;       end;      pnwynik.caption:=floattostr(wynik);    end;    end;     1: begin //obsługa metody prostok±tów z niedomiarem    if rb1.checked     begin      i:=1 n       begin        xi:= strtofloat(edod.text) + i*h;        wynik:= wynik + f1(xi)*h;       end;      pnwynik.caption := floattostr(wynik);     end;    if rb2.checked     begin      i:=1 n       begin        xi:=strtofloat(edod.text) + i*h;        wynik:= wynik + f2(xi)*h;       end;      pnwynik.caption:=floattostr(wynik);     end;          if rb3.checked       begin        i:=0 n-1         begin          xi:=strtofloat(edod.text)+i*h;          wynik:= wynik + f3(xi)*h;       end;      pnwynik.caption:=floattostr(wynik);   end; end; end; end;   procedure tform1.edprzedzialyexit(sender: tobject); begin  if (strtofloat(edprzedzialy.text)<10000) or     (strtofloat(edprzedzialy.text)>100000000)    begin    showmessage('podaj liczbę z przedziału [10000 - 100000000].');    edprzedzialy.setfocus;   end;  if frac(strtofloat(edprzedzialy.text))<>0 {sprawdzamy czy została wprowadzona liczba całkowita}   begin    showmessage('podaj liczbę całkowitą.');    edprzedzialy.setfocus;   end; end;  procedure tform1.edodexit(sender: tobject); begin  if strtofloat(edod.text)>=strtofloat(eddo.text)   begin    showmessage('podaj liczbę mniejsz± niż górna granica całkowania.');    edod.setfocus;   end; end;  procedure tform1.eddoexit(sender: tobject); begin if strtofloat(eddo.text)<=strtofloat(edod.text)   begin    showmessage('podaj liczbę większą niż dolna granica całkowania.');    eddo.setfocus;   end;   end;    function tform1.calkanadmiar (odx,dox:extended; n:integer; f:fx):extended; //trapez z nadmiarem var i:integer;  xi,h,wynik:extended; begin     wynik:=0;     h:=(dox-odx)/n; i:= 0 n-1     begin         wynik:=f(xi)*h+wynik;         xi:=xi+h;     end;     result:=wynik;  end;      function tform1.calkaniedomiar (odx,dox:extended; n:integer; f:fx):extended; //trapez z niedomiarem var i:integer;  xi,h,wynik:extended; begin     wynik:=0;     h:=(dox-odx)/n; i:= 1 n     begin         wynik:=f(xi)*h+wynik;         xi:=xi+h;     end;     result:=wynik; end;   function tform1.calka (odx,dox:extended; n:integer; f:fx):extended;  //trapez  var i:integer;  xi,h,wynik:extended; begin     wynik:=0;     h:=(dox-odx)/n; i:= 1 n-1     begin         wynik:=f(xi)+wynik;         xi:=xi+h;     end;     wynik:=(f(odx) + f(dox) + wynik)*h/2;     result:=wynik; end;   end. 

i think helpful you

case ( rgmetoda.itemindex ) of   2 : begin calkanadmiar;    end;    3 : begin calkaniedomiar; end;       else begin                    //call other function   end; end;  

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -