Написание программы игры "Жизнь" на Pascal 7.0, страница 5

  procedure Schet;

  Begin

  if Dlina > 0 then Begin

    xDelta := Dlina/Data.Guantit;

    x := Data.DownLimit;

    xFinish := Data.UpLimit;

  end

  else Begin

    xDelta := -Dlina/Data.Guantit;

    x := Data.UpLimit;

    xFinish := Data.DownLimit;

  end;

  xDelta2 := xDelta/2;

    y1 := FunctiyaInt.Run(x);

  While x <= xFinish do Begin

    y0 := y1;

    x := x + xDelta;

    y1 := FunctiyaInt.Run(x);

    Summa := Summa + xDelta2*(y0+y1);

    Pogreshnost := Pogreshnost + xDelta2*Abs(y0-y1);

  end;

  if x <> xFinish then Begin

    y0 := y1;

    y1 := FunctiyaInt.Run(xFinish);

    Summa := Summa + (xFinish - x)/2*(y0+y1);

    Pogreshnost := Pogreshnost + (xFinish - x)/2*Abs(y0-y1);

  end;

  End;

Begin

Summa := 0;

Pogreshnost := 0;

Dlina := Data.UpLimit-Data.DownLimit;

Schet;

While (Pogreshnost > Data.Accuracy) or (Data.Guantit<>$FFFFFFFF) do Begin

  if Data.Accuracy < $80000000 then Data.Accuracy := $FFFFFFFF

    else Data.Accuracy := Data.Accuracy*2;

  Schet;

end;

if Dlina > 0 then Data.Result := Summa

  else Data.Result := -Summa;

Data.Tochnost := Pogreshnost;

End;

procedure TMethodTrapeciy.RunWithNewData(NData: TDataIntegral);

Begin

NewData(NData);

if Report.Count = 0 then Run;

End;

//------------ Метод Симпсона ---------

procedure TMethodSimpsona.Run;

Var Dlina, x, xDelta, xDelta2, xFinish, Summa, Pogreshnost,

    y0, y1 : Real;

  procedure Schet;

  Begin

  if Dlina > 0 then Begin

    xDelta := Dlina/Data.Guantit;

    x := Data.DownLimit;

    xFinish := Data.UpLimit;

  end

  else Begin

    xDelta := -Dlina/Data.Guantit;

    x := Data.UpLimit;

    xFinish := Data.DownLimit;

  end;

  xDelta2 := xDelta/2;

    y1 := FunctiyaInt.Run(x);

  While x <= xFinish do Begin

    y0 := y1;

    x := x + xDelta;

    y1 := FunctiyaInt.Run(x);

    Summa := Summa + xDelta2*(y0+y1);

    Pogreshnost := Pogreshnost + xDelta2*Abs(y0-y1);

  end;

  if x <> xFinish then Begin

    y0 := y1;

    y1 := FunctiyaInt.Run(xFinish);

    Summa := Summa + (xFinish - x)/2*(y0+y1);

    Pogreshnost := Pogreshnost + (xFinish - x)/2*Abs(y0-y1);

  end;

  End;

Begin

Summa := 0;

Pogreshnost := 0;

Dlina := Data.UpLimit-Data.DownLimit;

Schet;

While (Pogreshnost > Data.Accuracy) or (Data.Guantit<>$FFFFFFFF) do Begin

  if Data.Guantit < $7FFFFFFF then Data.Guantit := $FFFFFFFF

    else Data.Guantit := Data.Guantit*2;

  Schet;

end;

if Dlina > 0 then Data.Result := Summa

  else Data.Result := Pogreshnost;

Data.Tochnost := Pogreshnost;

End;

procedure TMethodSimpsona.RunWithNewData(NData: TDataIntegral);

Begin

NewData(NData);

NData.Result := 10;

if Report.Count = 0 then Run;

End;

//--------------Выбор метода интегрирования из имеющихся---------

function CreateMethodIntegrirovaniya(Method: StrMethodIntegral;

         Var Protocol: TStringList): TMethodIntegral;

Var Trapeciya: TMethodTrapeciy;

    Simpson: TMethodSimpsona;

    MethodInt: TMethodIntegral;

Begin

if Method = 'трапеция' then Begin

  Trapeciya := TMethodTrapeciy.CreateWithReport(Protocol);

  CreateMethodIntegrirovaniya := Trapeciya;

end

  else if Method = 'симсоны' then Begin

    Simpson := TMethodSimpsona.CreateWithReport(Protocol);

    CreateMethodIntegrirovaniya := Simpson;

    end

    else Begin Protocol.Add('Метод интегрирования не инициализирован.');

      CreateMethodIntegrirovaniya := nil;

    end;

End;

end.

unit Integrirovanie;

interface

Uses Classes, SysUtils, MetodIntegrirovaniya, WorkWithText;

Type

  TIntegral = class(TWorkWithParameter)

  private

    Data: TDataIntegral;

    Int: TMethodIntegral;

  public

    constructor Create;

    procedure Free;

    procedure Schetat(Var SList: TStringList);

  end;

implementation

constructor TIntegral.Create;

Begin

inherited Create;

End;

procedure TIntegral.Free;

Begin

inherited Free;

End;

procedure TIntegral.Schetat(Var SList: TStringList);

Var i: Integer;

    s: String;

Begin

           {Подготовка даных}

StrListToFunctiya('Функция', Data.Functiya, SList);

StrListToNumber('Предел От', Data.DownLimit, SList);