contoh Uas
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
edini: TEdit;
edlalu: TEdit;
Label5: TLabel;
ComboBox1: TComboBox;
Label6: TLabel;
edtarif: TEdit;
Button1: TButton;
StringGrid1: TStringGrid;
Label7: TLabel;
edtotal: TEdit;
ednama: TEdit;
edkode: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function terpakai(a:integer;b:integer):integer;
function tarif(a:string):integer;
function total(c:integer;d:integer):integer;
end;
var
Form1: TForm1;
jumlah:integer;
implementation
{$R *.dfm}
function TForm1.terpakai(a:integer;b:integer):integer;
begin
terpakai:=a-b;
end;
function TForm1.tarif(a:string):integer;
begin
if a=’rumah’ then begin
tarif:=3000;
end else if a=’mesjid’ then begin
tarif:=2000;
end else if a=’kantor’ then begin
tarif:=5000;
end;
end;
function TForm1.total(c:integer;d:integer):integer;
begin
total:= c*d;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ComboBox1.Items.Add(‘rumah’);
ComboBox1.Items.Add(‘mesjid’);
ComboBox1.Items.Add(‘kantor’);
StringGrid1.ColCount:=8;
StringGrid1.RowCount:=6;
StringGrid1.ColWidths[0]:=20;
StringGrid1.ColWidths[1]:=100;
StringGrid1.ColWidths[2]:=200;
StringGrid1.Cells[1,0]:=’Kode_pelanggan’;
StringGrid1.Cells[2,0]:=’nama’;
StringGrid1.Cells[3,0]:=’MBI’;
StringGrid1.Cells[4,0]:=’MBL’;
StringGrid1.Cells[5,0]:=’terpakai’;
StringGrid1.Cells[6,0]:=’tarif’;
StringGrid1.Cells[7,0]:=’total’;
jumlah:=0;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
x:integer;
y:integer;
hasil:integer;
pentotalan:integer;
pentarifan:string;
a:string;
b:integer;
begin
StringGrid1.Cells[1,StringGrid1.Row]:=edkode.Text;
StringGrid1.Cells[2,StringGrid1.Row]:=ednama.Text;
StringGrid1.Cells[3,StringGrid1.Row]:=edini.Text;
StringGrid1.Cells[4,StringGrid1.Row]:=edlalu.Text;
x:=StrToInt(edini.Text);
y:=StrToInt(edlalu.Text);
hasil:=terpakai(x,y);
StringGrid1.Cells[5,StringGrid1.Row]:=IntToStr(hasil);
a:=ComboBox1.Text;
StringGrid1.Cells[6,StringGrid1.Row]:=IntToStr(tarif(a)) ;
pentotalan:= total(hasil,tarif(a));
StringGrid1.Cells[7,StringGrid1.Row]:= IntToStr(pentotalan);
StringGrid1.Row:=StringGrid1.Row+1;
jumlah:=jumlah+pentotalan;
edtotal.Text:=IntToStr(jumlah);
end;
end.
Blog;zulfiandri.wordpress.com

Tinggalkan Balasan