All pastes #547424 Raw Edit

Someone

public text v1 · immutable
·published 2007-06-07 11:43 UTC
rendered paste body
program Wykres;
uses Crt, Graph;
var a,b,c:integer;
    i:integer;
    min,max:real;
    r:real;
    pole:real;
    x1,x2:real;
    s:string;
    ch:char;

const dokladnosc = 0.0001;
      skalax = 6;
      skalay = 6;

function f(x:real):real;
begin
  f:=x*abs(x+1)-x;
end;

begin
  while ch<>'0' do begin
    ClrScr;
    Writeln('1. Obliczanie pola pod wykresem funkcji');
    Writeln('2. Pomoc');
    Writeln;
    Writeln('0. Wyj˜cie');
    ch:=ReadKey;
    if ch = '1' then begin
      Writeln;
      repeat
        repeat
          Writeln('Wprowad« przedziaˆ minimalny:');
          Readln(s);
          Val(s, min, c);
          if c <> 0 then begin
            Writeln('Wprowadzone dane nie s&#260; liczb&#260;. Spr&#728;buj jeszcze raz');
            Writeln;
          end;
        until c = 0;
        repeat
          Writeln('Wprowad« przedziaˆ maksymalny:');
          Readln(s);
          Val(s, max, c);
          if c <> 0 then begin
            Writeln('Wprowadzone dane nie s&#260; liczb&#260;. Spr&#728;buj jeszcze raz');
            Writeln;
          end;
        until c = 0;
        if max <= min then begin
          Writeln;
          Writeln('Przedziaˆ maksymalny nie mo&#318;e by&#8224; r&#728;wny/mniejszy od przedziaˆu minimalnego');
          Writeln;
        end;
      until max > min;
      i:=0;
      InitGraph(a,b,'');
      SetBkColor(DarkGray);
      SetColor(LightGray);
      ClearViewport;
      Line(GetMaxX div 2, 10, GetMaxX div 2, GetMaxY - 10);
      Line(GetMaxX div 2, 10, GetMaxX div 2 + 10, 20);
      Line(GetMaxX div 2, 10, GetMaxX div 2 - 10, 20);
      Line(10, GetMaxY div 2, GetMaxX - 10, GetMaxY div 2);
      Line(GetMaxX - 10, GetMaxY div 2, GetMaxX - 20, GetMaxY div 2 - 10);
      Line(GetMaxX - 10, GetMaxY div 2, GetMaxX - 20, GetMaxY div 2 + 10);
      SetLineStyle(DashedLn, 0, 1);
      SetColor(LightGray);
      Line(GetMaxX div 2 + round(min)*skalax, 10, GetMaxX div 2 + round(min)*skalax, GetMaxY - 10);
      Line(GetMaxX div 2 + round(max)*skalax, 10, GetMaxX div 2 + round(max)*skalax, GetMaxY - 10);
      SetColor(LightGreen);
      SetLineStyle(SolidLn, 0, 1);
      Line(GetMaxX div 2 + round(min)*skalax, GetMaxY div 2 - 1, GetMaxX div 2 + round(min)*skalax, GetMaxY div 2 - round(f(min)/skalay));
      Line(GetMaxX div 2 + round(max)*skalax, GetMaxY div 2 - 1, GetMaxX div 2 + round(max)*skalax, GetMaxY div 2 - round(f(max)/skalay));
      SetColor(Cyan);
      Str(round(min), s);
      OutTextXY(GetMaxX div 2 + round(min)*skalax - 7, GetMaxY div 2 + 5, s);
      Str(round(max), s);
      OutTextXY(GetMaxX div 2 + round(max)*skalax - 7, GetMaxY div 2 + 5, s);
      i:=0;
      MoveTo(GetMaxX div 2 + i*skalax, GetMaxY div 2 - round(f(i)/skalay));
      while i <= 70 do begin
        SetColor(Yellow);
        LineTo(GetMaxX div 2 + i*skalax, GetMaxY div 2 - round(f(i)/skalay));
        if (i > min) and (i < max) then begin
          SetColor(Cyan);
          Line(GetMaxX div 2 + i*skalax, GetMaxY div 2 - 1, GetMaxX div 2 + i*skalax, GetMaxY div 2 - round(f(i)/skalay)+1);
        end;
        i:=i+1;
      end;
      x1:=min;
      SetColor(White);
      pole:=0;
      while x1 <= max-dokladnosc do begin
        x2:=x1+dokladnosc;
        pole:=pole + ((f(x1)+f(x2))*dokladnosc)/2;
        x1:=x1+dokladnosc;
      end;
      Writeln('Pole pod krzyw&#260;: ', pole:0:5);
      ReadKey;
      CloseGraph;
    end;
    if ch = '2' then begin
      ClrScr;
      Writeln('Program oblicza pole pod wykresem funkcji okre˜lonej wzorem x*abs(x+1)-x.');
      Writeln('U&#318;ytkownik podaje minimalny i maksymalny przedziaˆ,');
      Writeln('w kt&#728;rym pole zostanie obliczone');
      Writeln;
      Writeln;
      Writeln('Autor: Aleksandra Dzier&#318;ek');
      ReadKey;
    end;
  end;
end.