ahlan wa sahlan saudaraku :)

Jumat, 29 Maret 2013

program statistika deskriptif dengan delphi

assalamu'alaikum ....
saya pengen ngeshare buat temen2 yang pengen tau gimana sih caranya buat program statistika deskriptif (minitab mini) pake program delphi ...
ini nih sintagnya, di program ini kita pake 2 form ...




a.      Form 1
unit tugas1;

interface

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

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Edit1: TEdit;
    Edit2: TEdit;
    StringGrid1: TStringGrid;
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button3Click(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  i,j,k,V,D,a: integer;
  Urut,b: real;
  Xbar,Varian: array [1..100] of real;
  X: array [1..100,1..100] of real;

implementation
uses Soal1_1;
{$R *.dfm}

procedure TForm1.Button3Click(Sender: TObject);
begin
application.terminate;
end;

procedure TForm1.Edit1Change(Sender: TObject);
begin
stringgrid1.ColCount:=strtoint(edit1.Text)+1;
if strtoint(edit1.Text)= 0 then
stringgrid1.FixedCols:=0
else stringgrid1.FixedCols:=1;
for i:=1 to strtoint(edit1.text) do
begin
stringgrid1.cells[i,0]:='X'+inttostr(i);
end;
end;

procedure TForm1.Edit2Change(Sender: TObject);
begin
stringgrid1.RowCount:=strtoint(edit2.Text)+1;
if strtoint(edit2.Text)=0 then
stringgrid1.FixedRows:=0
else stringgrid1.FixedRows:=1;
for j:=1 to strtoint(edit2.text) do
begin
stringgrid1.cells[0,j]:=inttostr(j);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
stringgrid1.FixedCols:=0;
stringgrid1.FixedRows:=0;
edit1.Text:='0';
edit2.Text:='0';
stringgrid1.ColCount:=0;
stringgrid1.RowCount:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
V:=strtoint(edit1.Text);
D:=strtoint(Edit2.Text);
form2.Show;
form2.stringgrid1.RowCount:=V+1;
for j:=1 to V do
begin
form2.stringgrid1.Cells[0,j]:='X'+inttostr(j);
form2.StringGrid1.RowCount:=V+1;
end;

for i:=1 to V do
begin
Xbar[i]:=0;
for j:=1 to D do
begin
Xbar[i]:=Xbar[i]+((strtofloat(stringgrid1.Cells[i,j])/D));
end;
form2.StringGrid1.Cells[1,i]:=floattostr(Xbar[i]);
end;

for i:=1 to V do
begin
Varian[i]:=0;
for j:=1 to D do
begin
Varian[i]:=Varian[i]+(sqr(Xbar[i]-strtofloat(stringgrid1.Cells[i,j]))/(D-1));
end;
form2.StringGrid1.Cells[2,i]:=floattostr(Varian[i]);
form2.StringGrid1.Cells[3,i]:=floattostr(sqrt(Varian[i]));
end;

for i:=1 to V do
begin
for j:=1 to D do
begin
X[i,j]:=strtofloat(stringgrid1.Cells[i,j]);
end;
end;

a:=(D+1) div 2;
b:=(D+1)/2;
for i:=1 to V do
begin
for j:=1 to D-1 do
begin
for k:=j+1 to D do
begin
if X[i,j]>X[i,k] then
begin
Urut:=X[i,j];
X[i,j]:=X[i,k];
X[i,k]:=Urut;
end;
end;
end;
form2.StringGrid1.Cells[4,i]:=floattostr(X[i,1]);
form2.StringGrid1.Cells[5,i]:=floattostr(X[i,D]);
form2.StringGrid1.Cells[6,i]:=floattostr(X[i,a]+((b-a)*(X[i,a+1]-X[i,a])));
end;
end;

end.

b.      Form 2
unit tugas1a;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls;
type
  TForm2 = class(TForm)
    Label1: TLabel;
    StringGrid1: TStringGrid;
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.FormCreate(Sender: TObject);
begin
  stringgrid1.Cells[1,0]:='mean';
  stringgrid1.Cells[2,0]:='var';
  stringgrid1.Cells[3,0]:='SD';
  stringgrid1.Cells[4,0]:='min';
  stringgrid1.Cells[5,0]:='max';
  stringgrid1.Cells[6,0]:='median';
end;
end.

ini ni hasilnya setelah di run
ini tampilan form 1 untuk memasukkan data
  
dan tampilan form 2 untuk hasilnya 

di coba ya, semoga berhasil dan bermanfaat :)

Tidak ada komentar:

Posting Komentar