Deskripsi :
Program kalkulator ini merupakan kalkulator bertipe standar bukan scientic karena fungsi-fungsi penghitungan yang ada masih sederhana seperti tambah, kurang, bagi, kali, akar, mod (sisa pembagian), dan sebagainya. Model dan style dari kalkulator yang saya buat menyerupai kalkulator yang ada pada windows xp. Saya membuat program ini dengan bahasa pemrograman delphi 7 dengan komponen standar yang ada di delphi 7 tersebut.
Source code Program :
- type
- TFKalkulator = class(TForm)
- b0: TBitBtn;
- b1: TBitBtn;
- b4: TBitBtn;
- b7: TBitBtn;
- bMinus: TBitBtn;
- b2: TBitBtn;
- b5: TBitBtn;
- b8: TBitBtn;
- bTitik: TBitBtn;
- b3: TBitBtn;
- b6: TBitBtn;
- b9: TBitBtn;
- bTambah: TBitBtn;
- bKurang: TBitBtn;
- bKali: TBitBtn;
- bBagi: TBitBtn;
- bHasil: TBitBtn;
- BitBtn18: TBitBtn;
- bMod: TBitBtn;
- bAkar: TBitBtn;
- EdTampil: TEdit;
- bClear: TBitBtn;
- BitBtn22: TBitBtn;
- bBackspace: TBitBtn;
- MainMenu1: TMainMenu;
- XPManifest1: TXPManifest;
- Pengaturan1: TMenuItem;
- Clear1: TMenuItem;
- Copy1: TMenuItem;
- Paste1: TMenuItem;
- N1: TMenuItem;
- Keluar1: TMenuItem;
- Bantuan1: TMenuItem;
- BukuManual1: TMenuItem;
- VideoTutorial1: TMenuItem;
- N2: TMenuItem;
- HakCipta1: TMenuItem;
- Timer1: TTimer;
- Panel1: TPanel;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Timer2: TTimer;
- procedure FormShow(Sender: TObject);
- procedure b1Click(Sender: TObject);
- procedure b2Click(Sender: TObject);
- procedure b3Click(Sender: TObject);
- procedure b4Click(Sender: TObject);
- procedure b5Click(Sender: TObject);
- procedure b6Click(Sender: TObject);
- procedure b7Click(Sender: TObject);
- procedure b8Click(Sender: TObject);
- procedure b9Click(Sender: TObject);
- procedure b0Click(Sender: TObject);
- procedure bClearClick(Sender: TObject);
- procedure bTambahClick(Sender: TObject);
- procedure bTitikClick(Sender: TObject);
- procedure bKurangClick(Sender: TObject);
- procedure bKaliClick(Sender: TObject);
- procedure bBagiClick(Sender: TObject);
- procedure bHasilClick(Sender: TObject);
- procedure bBackspaceClick(Sender: TObject);
- procedure bAkarClick(Sender: TObject);
- procedure bModClick(Sender: TObject);
- procedure bMinusClick(Sender: TObject);
- procedure Clear1Click(Sender: TObject);
- procedure Copy1Click(Sender: TObject);
- procedure Paste1Click(Sender: TObject);
- procedure Timer1Timer(Sender: TObject);
- procedure Keluar1Click(Sender: TObject);
- procedure Timer2Timer(Sender: TObject);
- procedure BitBtn18Click(Sender: TObject);
- procedure HakCipta1Click(Sender: TObject);
- private
- { Private declarations }
- procedure hitung();
- public
- { Public declarations }
- end;
- var
- FKalkulator: TFKalkulator;
- hasil,temp, simbol, data : string;
- klik : Integer;
- implementation
- uses StrUtils;
- {$R *.dfm}
- procedure TFKalkulator.hitung();
- var nilai_real : real; // hasil yg bersifat real
- nilai_int : Integer; // hasil yg bersifat integer
- begin
- // kondisi jika operand baru pertama kali diperintahkan
- if klik=1 then
- hasil :=EdTampil.Text
- else
- data := EdTampil.Text;
- // inisialisasi
- nilai_real := 0;
- // kondisi perhitungan jika ditemukan simbol
- if simbol = '+' then
- begin
- nilai_real := (StrToFloat(hasil)+StrToFloat(data));
- hasil := FloatToStr(nilai_real);
- end
- else if simbol = '-' then
- begin
- nilai_real := (StrToFloat(hasil)-StrToFloat(data));
- hasil := FloatToStr(nilai_real);
- end
- else if simbol = '/' then
- begin
- nilai_real := (StrToFloat(hasil)/strToFloat(data));
- hasil := FloatToStr(nilai_real);
- end
- else if simbol = 'X' then
- begin
- nilai_real := (StrToFloat(hasil)*StrToFloat(data));
- hasil := FloatToStr(nilai_real);
- end
- else if simbol = '%' then
- begin
- nilai_int := (StrToInt(hasil) mod StrToInt(data));
- hasil := IntToStr(nilai_int);
- end
- else if simbol = 'sqrt' then
- begin
- nilai_real := sqrt(StrToFloat(hasil));
- hasil := FloatToStr(nilai_real);
- end
- else if simbol = '1/x' then
- begin
- nilai_real := 1/(StrToFloat(hasil));
- hasil := FloatToStr(nilai_real);
- end
- else if simbol = '=' then
- hasil := FloatToStr(nilai_real);
- end;
- procedure TFKalkulator.FormShow(Sender: TObject);
- begin
- //EdTampil.al :=
- EdTampil.Text := '0';
- // inisialisasi variabel global
- temp := ''; // menyimpan sementara bilangan di EdTampil
- data := ''; // memindahkan hasil dari temp agar bersifat permanen
- hasil := ''; // hasil perhitungan
- simbol := ''; // operand type
- klik := 0; //bnyaknya klik suatu operand
- Panel1.Visible := False;
- Timer1.Enabled := False;
- Timer2.Enabled := False;
- end;
- procedure TFKalkulator.b1Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'1';
- end;
- procedure TFKalkulator.b2Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'2';
- end;
- procedure TFKalkulator.b3Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'3';
- end;
- procedure TFKalkulator.b4Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'4';
- end;
- procedure TFKalkulator.b5Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'5';
- end;
- procedure TFKalkulator.b6Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'6';
- end;
- procedure TFKalkulator.b7Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'7';
- end;
- procedure TFKalkulator.b8Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'8';
- end;
- procedure TFKalkulator.b9Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'9';
- end;
- procedure TFKalkulator.b0Click(Sender: TObject);
- begin
- if (EdTampil.Text = '0') then
- EdTampil.Clear
- else if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'0';
- end;
- procedure TFKalkulator.bTitikClick(Sender: TObject);
- begin
- if (klik>1) then
- begin
- EdTampil.Clear;
- klik:=1;
- end;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'.';
- end;
- procedure TFKalkulator.bMinusClick(Sender: TObject);
- begin
- if ((EdTampil.Text = '0') OR (klik>1)) then
- EdTampil.Clear;
- temp := EdTampil.Text;
- EdTampil.Text := temp+'-';
- end;
- procedure TFKalkulator.bClearClick(Sender: TObject);
- begin
- FormShow(Sender); // tampilkan dlm keadaan awal
- end;
- procedure TFKalkulator.bTambahClick(Sender: TObject);
- begin
- klik:=klik+1;
- //ShowMessage(''+IntToStr(klik));
- hitung();
- if klik=1 then
- EdTampil.Text := ''
- else
- EdTampil.Text := hasil;
- simbol := '+';
- temp := '';
- end;
- procedure TFKalkulator.bKurangClick(Sender: TObject);
- begin
- klik:=klik+1;
- hitung();
- if klik=1 then
- EdTampil.Text := ''
- else
- EdTampil.Text := hasil;
- simbol := '-';
- temp := '';
- end;
- procedure TFKalkulator.bKaliClick(Sender: TObject);
- begin
- klik:=klik+1;
- hitung();
- if klik=1 then
- EdTampil.Text := ''
- else
- EdTampil.Text := hasil;
- simbol := 'X';
- temp := '';
- end;
- procedure TFKalkulator.bBagiClick(Sender: TObject);
- begin
- klik:=klik+1;
- hitung();
- if klik=1 then
- EdTampil.Text := ''
- else
- EdTampil.Text := hasil;
- simbol := '/';
- temp := '';
- end;
- procedure TFKalkulator.bModClick(Sender: TObject);
- begin
- klik:=klik+1;
- hitung();
- if klik=1 then
- EdTampil.Text := ''
- else
- EdTampil.Text := hasil;
- simbol := '%';
- temp := '';
- end;
- procedure TFKalkulator.bAkarClick(Sender: TObject);
- begin
- klik:=klik+1;
- if klik=1 then
- begin
- simbol := 'sqrt';
- hitung();
- EdTampil.Text := hasil;
- end
- else
- begin
- hitung();
- EdTampil.Text := hasil;
- end;
- temp := '';
- klik:=0;
- simbol:= '';
- end;
- procedure TFKalkulator.BitBtn18Click(Sender: TObject);
- begin
- klik:=klik+1;
- if klik=1 then
- begin
- simbol := '1/x';
- hitung();
- EdTampil.Text := hasil;
- end
- else
- begin
- hitung();
- EdTampil.Text := hasil;
- end;
- temp := '';
- klik:=0;
- simbol:= '';
- end;
- procedure TFKalkulator.bHasilClick(Sender: TObject);
- begin
- klik:=klik+1;
- hitung();
- EdTampil.Text := hasil;
- temp := '';
- klik:=0;
- simbol:= '';
- end;
- procedure TFKalkulator.bBackspaceClick(Sender: TObject);
- var pjg : Integer;
- begin
- pjg := (EdTampil.GetTextLen); // panjang karakter dalam EdTampil
- EdTampil.Text := LeftStr(EdTampil.Text, pjg-1); // Tampilkan karakter sebanyak pjg-1 dari kiri
- if pjg = 1 then
- EdTampil.Text := '0';
- end;
- procedure TFKalkulator.Clear1Click(Sender: TObject);
- begin
- bClear.Click;
- end;
- procedure TFKalkulator.Copy1Click(Sender: TObject);
- begin
- EdTampil.SelectAll;
- EdTampil.CopyToClipboard;
- end;
- procedure TFKalkulator.Paste1Click(Sender: TObject);
- begin
- EdTampil.Clear;
- EdTampil.ReadOnly := False;
- EdTampil.PasteFromClipboard;
- EdTampil.ReadOnly := True;
- end;
- procedure TFKalkulator.Timer1Timer(Sender: TObject);
- begin
- AlphaBlend := True;
- Panel1.Visible := True;
- if Panel1.Height = 208 then
- begin
- Timer2.Enabled := True;
- end
- else
- begin
- Panel1.Height := Panel1.Height +1;
- if (Panel1.Height mod 4=0) then
- begin
- Label1.Top := Label1.Top+1;
- Label2.Top := Label2.Top+1;
- Label3.Top := Label3.Top+1;
- end;
- end;
- end;
- procedure TFKalkulator.Keluar1Click(Sender: TObject);
- begin
- Timer1.Enabled := True;
- end;
- procedure TFKalkulator.Timer2Timer(Sender: TObject);
- begin
- if AlphaBlendValue=180 then
- close
- else
- begin
- AlphaBlendValue := AlphaBlendValue-1;
- Caption := 'Kalkulator '+IntToStr(AlphaBlendValue-180);
- end;
- end;
- procedure TFKalkulator.HakCipta1Click(Sender: TObject);
- begin
- ShowMessage('Peogram kalkulator Standart Versi 1.0 '+#13#10+
- 'Dibuat oleh Mahasiswa Ilmu Komputer UB '+#13#10+
- 'ADHITYA AHMAD P (0510960002) '+#13#10+
- 'Angkatan 2005');
- end;
- end.
No comments:
Post a Comment