Search

Kamis, 31 Oktober 2013

DERET FIBONACCY DELPHI 7

unit tugas3;

interface

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

type
  TForm1 = class(TForm)
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Label1: TLabel;
    ListBox1: TListBox;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    MainMenu1: TMainMenu;
    fi1: TMenuItem;
    WAKTU1: TMenuItem;
    PARABOLA1: TMenuItem;
    FIBONACCI1: TMenuItem;
    procedure BitBtn1Click(Sender: TObject);
    procedure BitBtn2Click(Sender: TObject);

  private
    { Private declarations }
    function FiboIterasi(const pInput: Integer): Double;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function TForm1.FiboIterasi(const pInput: Integer): Double;
var
  i: Integer;
  a, b, hasil : Double;
begin
  // Inisialisasi variabel
  hasil := 0;
  a := 1;
  b := 0;

  // mulai iterasi
  for i:=1 to pInput do
  begin
    hasil := a+b;
    a := b;
    b := hasil;
  end;

  // kembalikan hasil ke pemanggil
  Result := hasil;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var i,input : integer;
begin

try
  if trim(edit1.Text) <> '' then
    input:=strtoint(trim(edit1.Text))
  else
    input:=-1;
except
   exit;
end;

if input <= 0 then
  begin
    messagedlg('Input deret yang valid',mtError,[MbOK],0);
    exit;
  end;

if input >= 31 then
  begin
    messagebox(self.Handle,'Dibatas sampai 30 saja biar tidak error','hati-hati mas',MB_OK + MB_ICONWARNING);
    edit1.Clear;
    edit1.SetFocus;
    exit;
  end;

for i:=1 to input do
  listbox1.Items.Add(floattostr(fiboIterasi(i)));
  bitbtn1.Enabled:=false;
end;

procedure TForm1.BitBtn2Click(Sender: TObject);
begin
edit1.Clear;
listbox1.Clear;
edit1.SetFocus;
bitbtn1.Enabled:=true;
end;
end.


Tidak ada komentar:

Posting Komentar