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

    '.': if tochka or stepen then goto ErrorInCheslo

      else Begin tochka := True; SNumber[i] := ','; end;

    ',': if tochka or stepen then goto ErrorInCheslo

      else tochka := True;

    'E', 'e': if stepen then goto ErrorInCheslo

      else Begin stepen := True; j := i;

      end;

    '0'..'9': ;

    else goto ErrorInCheslo;

  end;

ErrorInCheslo: if i <= Length(SNumber) then

  Report.Add('Ошибка записи "' + s + '"')

else x := StrToFloat(SNumber);

End;

procedure TWorkWithParameter.StrListToFunctiya(s: String; Var x: String;

      Const SList: TStringList);

Var i: Integer;

    SFunctiya: String;

Label ErrorInCheslo;

Begin

if Not StrListPresenceOfNames(s, SFunctiya, SList) then Exit;

For i := 1 to Length(SFunctiya) do

  case SFunctiya[i] of

  'A'..'Z': SFunctiya[i] := Chr( Ord(SFunctiya[i]) + Ord('a') - Ord('A') );

  'a'..'z', '0'..'9', '(', ')', '^', '!', '+', '-', '/', '*': ;

  else goto ErrorInCheslo;

end;

ErrorInCheslo: if i <= Length(SFunctiya) then

  Report.Add('Ошибка записи "' + s + '"')

  else x := SFunctiya;

End;

end.

unit MetodIntegrirovaniya;

interface

Uses Classes, SysUtils, Functiya;

Type

  StrMethodIntegral = String[10];

  TDataIntegral = record

    Functiya: String;

    UpLimit, DownLimit, Result, Tochnost, Accuracy : Real;

    Guantit: Longword;

  End;

  TMethodIntegral = class(TObject)

    procedure Run; virtual; abstract;

    procedure RunWithNewData(NData: TDataIntegral); virtual; abstract;

  protected

    Data: TDataIntegral;

    FunctiyaInt: TFunctiya;

    Report: TStringList;

  public

    procedure NewData(NewData: TDataIntegral);

    procedure Check;

    function TakeOutError: TStringList;

    constructor Create;

    constructor CreateWithData(NData: TDataIntegral);

    constructor CreateWithReport(Var Protocol: TStringList);

    constructor CreateWithAll(NData: TDataIntegral; Var Protocol: TStringList);

    procedure FreeWithReport;

    procedure Free;

  End;

  TMethodTrapeciy = class(TMethodIntegral)

    procedure Run; override;

    procedure RunWithNewData(NData: TDataIntegral); override;

  End;

  TMethodSimpsona = class(TMethodIntegral)

    procedure Run; override;

    procedure RunWithNewData(NData: TDataIntegral); override;

  End;

function CreateMethodIntegrirovaniya(Method: StrMethodIntegral;

         Var Protocol: TStringList): TMethodIntegral;

implementation

constructor TMethodIntegral.Create;

Begin

inherited;

Report := TStringList.Create;

FunctiyaInt := TFunctiya.CreateWithReport(Report);

End;

constructor TMethodIntegral.CreateWithData(NData: TDataIntegral);

Begin

inherited Create;

Report := TStringList.Create;

FunctiyaInt := TFunctiya.CreateWithReport(Report);

NewData(NData);

End;

constructor TMethodIntegral.CreateWithReport(Var Protocol: TStringList);

Begin

inherited Create;

Report := Protocol;

FunctiyaInt := TFunctiya.CreateWithReport(Protocol);

End;

constructor TMethodIntegral.CreateWithAll(NData: TDataIntegral; Var Protocol: TStringList);

Begin

inherited Create;

Report := Protocol;

FunctiyaInt := TFunctiya.CreateWithReport(Protocol);

NewData(NData);

End;

procedure TMethodIntegral.Free;

Begin

FunctiyaInt.Free;

inherited;

End;

procedure TMethodIntegral.FreeWithReport;

Begin

Report.Free;

FunctiyaInt.Free;

inherited;

End;

function TMethodIntegral.TakeOutError: TStringList;

Begin

TakeOutError := Report;

End;

procedure TMethodIntegral.Check;

Begin

if Data.UpLimit = Data.DownLimit then

  Report.Add('Неправильно заданы пределы интегрирования.');

if Data.Tochnost < 0 then

  Report.Add('Точность не может быть отрицательной.');

if Data.Accuracy = 0 then

  Report.Add('Точность не может = 0.');

if (Data.Guantit = 0) then

  Report.Add('Нельзя интервал разбить на 0 отрезков.');

End;

procedure TMethodIntegral.NewData(NewData: TDataIntegral);

Begin

Data := NewData;

FunctiyaInt.NewFunctiya(NewData.Functiya);

Check;

End;

//------------ Метод трапеций ---------

procedure TMethodTrapeciy.Run;

Var Dlina, x, xDelta, xDelta2, xFinish, Summa, Pogreshnost, y0, y1 : Real;