Eugeniusz Jakubas |
Stąd można pobrać teksty źródłowe poniższych 57 programów w Pascalu pr-pascal.zip - 34 kB
22. Pole pod funkcją
Program Pole_pod_funkcja; uses Graph; var karta,tryb,n,k,iprz,j:integer; x,y,x1,x2,Dx,pole:real; function f(x:real):real; begin f:=(x*x*x-5*x)/5 end; begin karta:=detect; initGraph(karta,tryb,''); j:=20; setColor(darkGray); for n:=-320 div j to 320 div j do line(320+n*j,0,320+n*j,479); for n:=-240 div j to 240 div j do line(0,240+n*j,639,240+n*j); setColor(white); line(0,240,639,240); line(320,0,320,479); setColor(lightBlue); x1:=-3; x2:=4; x:=-320/j; Dx:=0.00025; repeat x:=x+Dx; y:=f(x); if abs(y)<240/j then putPixel(round(x*j+320),round(-y*j+240),lightBlue); if (x>x1) and (x<x2) then line(round(x*j+320),round(-y*j+240), round(x*j+320),240); until x>320/j; setColor(lightRed); iprz:=20; pole:=0; Dx:=(x2-x1)/iprz; for n:=1 to iprz do begin x:=x1+n*Dx-Dx/2; pole:=pole+f(x)*Dx; rectangle(round(j*(x1+(n-1)*Dx)+320),round(-j*f(x)+240), round(j*(x1+n*Dx)+320),240); end; setColor(white); line(0,240,639,240); line(320,0,320,479); writeLn(' Pole = ',pole:1:4); readln; closeGraph; end. |