program perhitungan sederhana di delphi
biasanya dalam matematika kita sering menemui perhitungan tambah, kali, bagi,pangkat dll. nah disini saya akan berikan contoh pembuatan program perhitungan sederhana dengan menggunakan bahasa pemrograman delphi.
source
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,math;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
ComboBox1: TComboBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
AResult : double;
begin
AResult := 0;
if ComboBox1.Text ='^' then
AResult := Power(StrToInt(Edit1.Text),StrToInt(Edit2.Text))
else if ComboBox1.Text ='+' then
AResult := StrToInt(Edit1.Text)+StrToInt(Edit2.Text)
else if ComboBox1.Text ='-' then
AResult := StrToInt(Edit1.Text)-StrToInt(Edit2.Text)
else if ComboBox1.Text ='/' then
begin
if StrToInt(Edit2.Text) = 0 then
AResult := 0
else
AResult := StrToInt(Edit1.Text)/StrToInt(Edit2.Text);
end
else if ComboBox1.Text ='*' then
AResult := StrToInt(Edit1.Text)+StrToInt(Edit2.Text);
Edit3.Text := FloatToStr(AResult);
end;
end.
hasilnya: