Upload
mardhiatus-sholihah
View
165
Download
3
Embed Size (px)
Citation preview
DELPHI TEXT
begin
edit1.Text:='tombol 1';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.text:='tombol 2';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
edit1.text:='tombol 3';
end;
end.
begin
label2.Caption:= edit1.Text;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
label2.Caption:='';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
end.
begin
label3.Caption := edit1.text;
label5.Caption := edit2.Text;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text := '';
edit2.Text := '';
label3.Caption := '';
label5.Caption := '';
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;
end.
DELPHI ARITMATIKA
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c:real;
begin
a:=strtofloat(edit1.Text);
b:=strtofloat(edit2.Text);
c:=A+B;
edit3.Text:=floattostr(c);
end;
end.
procedure TForm1.Button1Click(Sender: TObject);
var
a,b:integer;
c:real;
begin
a:=strtoint(edit1.text);
b:=strtoint(edit2.text);
c:=a/b;
edit3.text:= floattostr(c)
end;
end.
var
a,b,c:integer;
begin
a:=strtoint(edit1.text);
b:=strtoint(edit2.text);
c:=SQR(A)+SQR(B)*B;
edit3.Text:=inttostr(c);
end;
end.
var
a,b,c :integer;
begin
a:=strtoint(edit1.text);
b:=strtoint(edit2.text);
c:=a mod b;
edit3.Text:=inttostr(c);
end;
end.
var
a,b,c:integer;
d:real;
begin
a:=strtoint(edit1.text);
b:=strtoint(edit2.text);
c:=strtoint(edit3.text);
d:=SQR(B)-(4*a*c);
label6.Caption:=floattostr(d);
end;
end.
var
a,t,s:integer;
luas,keliling:real;
begin
a:=strtoint(edit1.text);
t:=strtoint(edit2.text);
s:=strtoint(edit3.text);
luas:=1/2*a*t;
label7.Caption:=floattostr(luas);
keliling:=a+t+s;
label8.Caption:=floattostr(keliling);
end;
end.
var
r,luas,keliling:real;
begin
r:=strtofloat(edit1.text);
luas:= 3.14*SQR(r);
label6.Caption:=floattostr(luas);
keliling:=2*3.14*r;
label7.Caption:=floattostr(keliling);
end;
end.
var
gula,minyak,total:real;
aqua,indomie:integer;
begin
gula:=strtofloat(edit1.text);
minyak:=strtofloat(edit2.text);
aqua:=strtoint(edit3.text);
indomie:=strtoint(edit4.text);
total:=(10500*gula)+(6500*minyak)+(500*aqua)+(1500*indomie);
label6.Caption:=floattostr(total);
end;
end.
DELPHI PERCABANGAN
var
a:integer;
begin
a:=strtoint(edit1.text);
if a <0 then
begin
label2.Caption := 'negatif';
end;
if a>0 then
begin
label2.caption := 'positif';
label3.Caption := 'selamat';
end;
if a=0 then
begin
label2.Caption := 'bilangan nol';
end;
end;
end.
var
a,b:integer;
begin
a:=strtoint(edit1.text);
b:= a mod 2;
label3.Caption:=inttostr(b);
if (a>0) and (b=0) then
label4.Caption:='genap positif';
if (a<0) and (b=0) then
label4.Caption:='genap negatif';
if (a>0) and (b<>0) then
label4.Caption:='ganjil positif';
if (a<0) and (b<>0) then
label4.Caption:='ganjil negatif';
end;
end.
var
nilai:integer;
begin
nilai:=strtoint(edit1.text);
if (nilai >=79) and (nilai <=100) then
label3.Caption:='A';
if (nilai >=69) and (nilai <=78) then
label3.Caption:='B';
if (nilai >=59) and (nilai <=68) then
label3.Caption:='C';
if (nilai >=40) and (nilai <=58) then
label3.Caption:='D';
if (nilai >=0) and (nilai <=39) then
label3.Caption:='E';
end;
end.
var
indomie:integer;
beras,minyak,total,hitung:real;
begin
indomie:=strtoint(edit1.text);
beras:=strtofloat(edit2.text);
minyak:=strtofloat(edit3.text);
total:=(1500*indomie)+(6000*minyak)+(7000*beras);
if indomie <=30 then
begin
label6.Caption:=floattostr(total);
label7.Caption:='diskon 0%';
end;
if indomie >30 then
begin
hitung:=(total)-(0.1/100*total);
label6.Caption:=floattostr(hitung);
label7.Caption:='diskon 0.1%';
end;
end;
end.
DELPHI PERULANGAN
var
i:integer;
begin
for i:=1 to 10 do
memo1.lines.add('belajar perulangan');
end;
end.
var
i,jumlah,deret:integer;
begin
deret:=strtoint(edit1.text);
jumlah:=0;
for i:=1 to deret do
jumlah:=jumlah+i;
label2.caption:=inttostr(jumlah);
end;
end.
var
i,jumlah,faktorial:integer;
begin
faktorial:=strtoint(edit1.text);
jumlah:=1;
for i:= 1 to faktorial do
jumlah:=jumlah*i;
label2.Caption:=inttostr(jumlah);
end;
end.
var
x,n,jumlah,i:integer;
hasil:real;
begin
x:=strtoint(edit1.text);
n:=strtoint(edit2.text);
jumlah:=1;
for i := 1 to n do
jumlah:=jumlah *x;
hasil:=jumlah;
label5.Caption:=floattostr(hasil);
end;
end.
jumlah,i,n,x:integer;
hasil:real;
begin
x:=strtoint(edit1.text);
n:=strtoint(edit2.text);
jumlah:=1;
if n<0 then
begin
for i := 1 to -n do
jumlah:=jumlah*x;
hasil:=1/jumlah;
label4.Caption:=floattostr(hasil);
label5.Caption:='karena berpangkat negatif';
end;
if n=0 then
begin
hasil:=jumlah;
label4.Caption:=floattostr(hasil);
label5.Caption:='karena pangkat 0=1';
end;
if n>0 then
begin
for i := 1 to n do
jumlah:=jumlah*x;
hasil:=jumlah;
label4.Caption:=floattostr(hasil);
label5.Caption:='karena berpangkat positif';
end;
end;
end.
Latihan
var
x,n,jumlah,i:integer;
a,hasil:real;
begin
x:=strtoint(edit1.text);
n:=strtoint(edit2.Text);
a:=strtofloat(edit3.Text);
if a=0 then
begin
label4.Caption:='devide by zero';
end;
if a<>0 then
begin
if n>0 then
begin
jumlah:=1;
for i:=1 to n do
jumlah:=jumlah*x;
hasil:=jumlah/a;
label4.Caption:=floattostr(hasil);
end;
if n<0 then
begin
jumlah:=1;
for i:=1 to -n do
jumlah:=(jumlah*x);
hasil:=1/jumlah/a;
label4.Caption:=floattostr(hasil);
end;
if n=0 then
begin
jumlah:=1;
hasil:=1/a;
label4.Caption:=floattostr(hasil);
end;
end;
end;
end.