
Unit UCalculator;
Interface
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, xpPanel, StdCtrls, xpEdit, xpButton, xpWindow, xpBitBtn,
ImgList, CoolTrayIcon, TrayIcon;
Type
TForm1 = class(TForm)
xpPanel1: TxpPanel;
layar: TxpEdit;
satu: TxpButton;
dua: TxpButton;
lima: TxpButton;
enam: TxpButton;
sembilan: TxpButton;
tiga: TxpButton;
empat: TxpButton;
tujuh: TxpButton;
delapan: TxpButton;
nol: TxpButton;
enter: TxpButton;
clear: TxpButton;
kali: TxpButton;
bagi: TxpButton;
tambah: TxpButton;
kurang: TxpButton;
koma: TxpButton;
tutup: TxpBitBtn;
ImageBarUp: TImageList;
TrayIconBarUp: TCoolTrayIcon;
TrayNotifyBarUp: TTrayNotifyIcon;
procedure tutupClick(Sender: TObject);
procedure tambahClick(Sender: TObject);
procedure satuClick(Sender: TObject);
procedure duaClick(Sender: TObject);
procedure tigaClick(Sender: TObject);
procedure empatClick(Sender: TObject);
procedure limaClick(Sender: TObject);
procedure enamClick(Sender: TObject);
procedure tujuhClick(Sender: TObject);
procedure delapanClick(Sender: TObject);
procedure sembilanClick(Sender: TObject);
procedure nolClick(Sender: TObject);
procedure clearClick(Sender: TObject);
procedure kurangClick(Sender: TObject);
procedure enterClick(Sender: TObject);
procedure bagiClick(Sender: TObject);
procedure kaliClick(Sender: TObject);
procedure komaClick(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
end;
Var
Form1: TForm1;
implementation
{$R *.DFM}
// variabel dengan tipe global //
Var
FTombol : real;
Operasi : string;
procedure TForm1.tutupClick(Sender: TObject);
begin
application.terminate;
end;
//Inisialisasi Untuk Operasi Penjumlahan
procedure TForm1.tambahClick(Sender: TObject);
begin
Operasi := 'jumlah';
FTombol := StrToFloat(Layar.Text);
Layar.Clear;
end;
procedure TForm1.satuClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.duaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.tigaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.empatClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.limaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.enamClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.tujuhClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.delapanClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.sembilanClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.nolClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.clearClick(Sender: TObject);
var
AHitung, SAngka : real;
Hasil : string;
begin
Layar.Clear;
Hasil :='0' ;
end;
//Inisialisasi Untuk Operasi Pengurangan
procedure TForm1.kurangClick(Sender: TObject);
var
Angka: real;
TeksLayar: string;
begin
Operasi := 'kurang';
FTombol := -(StrToFloat(Layar.Text));
Layar.Text := TeksLayar;
Layar.Clear;
end;
//Prosesing pemanggilan inisialisasi dan algoritma penghitungan
procedure TForm1.enterClick(Sender: TObject);
var
AHitung, SAngka : real;
Hasil : string;
begin
SAngka := StrToFloat(Layar.Text);
Begin
if operasi = 'jumlah' then
AHitung := FTombol + SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
Begin
if operasi = 'bagi' then
AHitung := FTombol/SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
Begin
if operasi = 'kali' then
AHitung := FTombol*SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
Begin
if operasi = 'kurang' then
AHitung := FTombol + SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
end;
//Inisialisasi Untuk Operasi Pembagian
procedure TForm1.bagiClick(Sender: TObject);
begin
Operasi := 'bagi';
FTombol := StrToFloat(Layar.Text);
Layar.Clear;
end;
//Inisialisasi Untuk Operasi Perkalian
procedure TForm1.kaliClick(Sender: TObject);
begin
Operasi := 'kali';
FTombol := StrToFloat(Layar.Text);
Layar.Clear;
end;
procedure TForm1.komaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
end.
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, xpPanel, StdCtrls, xpEdit, xpButton, xpWindow, xpBitBtn,
ImgList, CoolTrayIcon, TrayIcon;
Type
TForm1 = class(TForm)
xpPanel1: TxpPanel;
layar: TxpEdit;
satu: TxpButton;
dua: TxpButton;
lima: TxpButton;
enam: TxpButton;
sembilan: TxpButton;
tiga: TxpButton;
empat: TxpButton;
tujuh: TxpButton;
delapan: TxpButton;
nol: TxpButton;
enter: TxpButton;
clear: TxpButton;
kali: TxpButton;
bagi: TxpButton;
tambah: TxpButton;
kurang: TxpButton;
koma: TxpButton;
tutup: TxpBitBtn;
ImageBarUp: TImageList;
TrayIconBarUp: TCoolTrayIcon;
TrayNotifyBarUp: TTrayNotifyIcon;
procedure tutupClick(Sender: TObject);
procedure tambahClick(Sender: TObject);
procedure satuClick(Sender: TObject);
procedure duaClick(Sender: TObject);
procedure tigaClick(Sender: TObject);
procedure empatClick(Sender: TObject);
procedure limaClick(Sender: TObject);
procedure enamClick(Sender: TObject);
procedure tujuhClick(Sender: TObject);
procedure delapanClick(Sender: TObject);
procedure sembilanClick(Sender: TObject);
procedure nolClick(Sender: TObject);
procedure clearClick(Sender: TObject);
procedure kurangClick(Sender: TObject);
procedure enterClick(Sender: TObject);
procedure bagiClick(Sender: TObject);
procedure kaliClick(Sender: TObject);
procedure komaClick(Sender: TObject);
Private
{ Private declarations }
Public
{ Public declarations }
end;
Var
Form1: TForm1;
implementation
{$R *.DFM}
// variabel dengan tipe global //
Var
FTombol : real;
Operasi : string;
procedure TForm1.tutupClick(Sender: TObject);
begin
application.terminate;
end;
//Inisialisasi Untuk Operasi Penjumlahan
procedure TForm1.tambahClick(Sender: TObject);
begin
Operasi := 'jumlah';
FTombol := StrToFloat(Layar.Text);
Layar.Clear;
end;
procedure TForm1.satuClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.duaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.tigaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.empatClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.limaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.enamClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.tujuhClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.delapanClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.sembilanClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.nolClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
procedure TForm1.clearClick(Sender: TObject);
var
AHitung, SAngka : real;
Hasil : string;
begin
Layar.Clear;
Hasil :='0' ;
end;
//Inisialisasi Untuk Operasi Pengurangan
procedure TForm1.kurangClick(Sender: TObject);
var
Angka: real;
TeksLayar: string;
begin
Operasi := 'kurang';
FTombol := -(StrToFloat(Layar.Text));
Layar.Text := TeksLayar;
Layar.Clear;
end;
//Prosesing pemanggilan inisialisasi dan algoritma penghitungan
procedure TForm1.enterClick(Sender: TObject);
var
AHitung, SAngka : real;
Hasil : string;
begin
SAngka := StrToFloat(Layar.Text);
Begin
if operasi = 'jumlah' then
AHitung := FTombol + SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
Begin
if operasi = 'bagi' then
AHitung := FTombol/SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
Begin
if operasi = 'kali' then
AHitung := FTombol*SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
Begin
if operasi = 'kurang' then
AHitung := FTombol + SAngka;
Hasil := FormatFloat('0.#####', AHitung);
Layar.Text := Hasil;
End;
end;
//Inisialisasi Untuk Operasi Pembagian
procedure TForm1.bagiClick(Sender: TObject);
begin
Operasi := 'bagi';
FTombol := StrToFloat(Layar.Text);
Layar.Clear;
end;
//Inisialisasi Untuk Operasi Perkalian
procedure TForm1.kaliClick(Sender: TObject);
begin
Operasi := 'kali';
FTombol := StrToFloat(Layar.Text);
Layar.Clear;
end;
procedure TForm1.komaClick(Sender: TObject);
begin
layar.Text := layar.Text + (sender as txpbutton).caption;
end;
end.