Eugeniusz Jakubas
programy źródłowe w Pascalu

Stąd można pobrać teksty źródłowe poniższych 57 programów w Pascalu pr-pascal.zip - 34 kB

32. Sieczna

Program Sieczna;
uses Graph;
var karta,tryb,n,siatka,j,xA,yA,xB,yB:integer;
    x,y,x1,x2,u:real;
function f(x:real):real;
begin
  f:=1/4*x*x+x-6;
end;
begin
  karta:=detect; initGraph(karta,tryb,'');
  j:=20; siatka:=20;
  setColor(darkGray); rectangle(0,0,639,479);
  for n:=-320 div siatka to 320 div siatka do
  begin
    line(320+n*siatka,0,320+n*siatka,479);
    line(0,240+n*siatka,639,240+n*siatka);
  end;
  setcolor(white);
  line(0,240,639,240); line(630,235,639,240); line(630,245,639,240);
  outtextxy(630,250,'X');
  line(320,0,320,479); line(315,9,320,0); line(320,0,325,9);
  outtextxy(330,8,'Y');
  for n:=-320 div j to 320 div j do
  begin
    line(320+n*j,238,320+n*j,242);
    line(318,240+n*j,322,240+n*j);
  end;
  x:=-320/j;
  repeat
    x:=x+1/j;
    putPixel(round(x*j+320),round(240-f(x)*j),yellow);
  until x>320/j;
  x2:=6;
  x1:=-1;
  u:=(f(x2)-f(x1))/(x2-x1); write('u = ',u:5:4);
  setColor(lightRed);
  xA:=round(x1*j+320); yA:=round(240-f(x1)*j); fillEllipse(xA,yA,3,3);
  xB:=round(x2*j+320); yB:=round(240-f(x2)*j); fillEllipse(xB,yB,3,3);
  line(0,round(u*xA+yA),639,round(u*(xA-639)+yA));
  line(xB,yB,xB,yA); line(xB,yA,xA,yA);
  readln; closegraph;
end.