+ -
当前位置:首页 → 问答吧 → delphi跪求代码··

delphi跪求代码··

时间:2011-09-25

来源:互联网

要求写一个类,类中包含两个方法,一个put方法用于接收样本数据,一个getdata方法用于返回样本分布情况,例如:区间小于一和五到十的样本数据有几个?区间个数不超过十个,要求区间个数和范围都可以随时修改。

作者: yuanzhiteng   发布时间: 2011-09-25

你跪对别人也没有用处,不如给点酬劳更实在。

作者: zhouzuoji   发布时间: 2011-09-25

Delphi(Pascal) code
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


type
  TSectionList = array of array[0..1] of Integer;

  TDataManage = class
    FData: array of Integer;

    procedure Put(A: array of Integer);
    function GetData(AIn: TSectionList; var AOut: array of Integer): Integer;
  end;

{ TSection }

function TDataManage.GetData(AIn: TSectionList; var AOut: array of Integer): Integer;
var
  I, J: Integer;
begin
  Result := 0;

  for I := 0 to High(AIn) do
    for J := 0 to High(FData) do
      if (FData[J] >= AIn[I][0]) and (FData[J] <= AIn[I][1]) then
      begin
        AOut[Result] := FData[J];
        Inc(Result)
      end;
end;

procedure TDataManage.Put(A: array of Integer);
var
  I, J: Integer;
begin
  J := Length(FData);
  SetLength(FData, J + Length(A));
  for I := 0 to High(A) do
    FData[J + I] := A[I]
end;

procedure TForm1.FormCreate(Sender: TObject);
var
  D: TDataManage;
  I: TSectionList;
  O: array of Integer;
  J, nCount: Integer;
begin
  D := TDataManage.Create;
  try
    D.Put([1,2,300,4,5,6,7,8,9,10]);
    D.Put([-110]);

    SetLength(I, 2);//2个区间
    I[0][0] := -5;//[-5,3]
    I[0][1] := 3;
    I[1][0] := 5;//[5,9]
    I[1][1] := 9;
    SetLength(O, 100);//开辟100个元素的数组空间来接收结果

    nCount := D.GetData(I, O);
    Memo1.Lines.Add('样本数据个数:' + IntToStr(nCount));
    Memo1.Lines.Add('样本数据:');
    for J := 0 to nCount - 1 do
      Memo1.Lines.Add(IntToStr(O[J]))
  finally
    D.Free
  end;

end;

end.

作者: s11ss   发布时间: 2011-09-25