Pages

Latihan 3 Struktur Data [Function]

Latihan 5 Pemrograman Visual

var
  Form1: TForm1;
  a,b,c,d,e:string;


procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case Combobox1.ItemIndex of
0:begin
edit1.Text:='nama';
edit2.Text:='alamat';
edit3.Text:='umur';
edit4.Text:='status';
edit5.Text:='aaa';
end;
1:begin
a:='aaaa';
b:='bbbb';
c:='cccc';
d:='dddd';
e:='eeee';
end;
2:begin
a:='kkkk';
b:='llll';
c:='mmmm';
d:='nnnn';
e:='oooo';
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
edit6.Text:='';
combobox1.ItemIndex:=-1;
radiogroup1.ItemIndex:=-1;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
edit1.Text:=a;
edit2.Text:=b;
edit3.Text:=c;
edit4.Text:=d;
edit5.Text:=e;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
close;
end;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
Case RadioGroup1.ItemIndex of
0:begin
edit6.Text:='4';
end;
1:begin
edit6.Text:='5';
end;
2:begin
edit6.Text:='6';
end;
end;
end;
end.


Latihan 10 Sistem Basis Data

View
with thisform
.text5.value=.text1.text
.text6.value=.text2.text
.text7.value=.text3.text
.text8.value=.text4.text
Endwith

Close
thisform.release()

Renew
with thisform
.text1.value=""
.text2.value=""
.text3.value=""
.text4.value=""
.text5.value=""
.text6.value=""
.text7.value=""
.text8.value=""
Endwith

Hasil Run


Latihan 2 Struktur Data [procedure]

Procedure 1

Procedure 2





Materi SBD

Silahkan download
MATERI 1
MATERI 2

Latihan 4 Pemrograman Visual



var
  Form1: TForm1;
  a,b,c:real;

procedure TForm1.RadioGroup1Click(Sender: TObject);
begin
case radiogroup1.ItemIndex of
0:begin
a:=3500;
end;
1:begin
a:=4000;
end;
2:begin
a:=5000;
end;
end;
edit1.Text:=floattostr(a+b+c);
end;

procedure TForm1.CheckBox1Click(Sender: TObject);
begin
if CheckBox1.Checked then
b:=2000;
edit1.Text:=floattostr(a+b+c);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
x,y,z:real;
begin
x:=strtofloat(edit1.text);
y:=strtofloat(edit2.Text);
z:=y-x;
edit3.text:=floattostr(z);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
checkbox1.Checked:=false;
a:=0;
b:=0;
c:=0;
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
radiogroup1.ItemIndex:=-1;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
begin
case combobox1.ItemIndex of
0:begin
c:=1000;
end;
end;
edit1.text:=floattostr(a+b+c);
end;
end.

Hasil Run

Latihan 9 Sistem Basis Data

Text2

with thisform

.text3.value=val(.text1.text)*val(.text2.text)

Endwith



Check1

with thisform

.text4.value="Anda mendapat diskon 30%"

.text5.value=val(.text3.text)-val(.text3.text)*0.3

.text6.value=val(.text3.text)*0.3

.check2.enabled=.f.

.check3.enabled=.f.

Endwith



Check2

with thisform

.text4.value="Anda mendapat diskon 10%"

.text5.value=val(.text3.text)-val(.text3.text)*0.1

.text6.value=val(.text3.text)*0.1

.check1.enabled=.f.

.check3.enabled=.f.

Endwith



Check3

with thisform

.text4.value="Anda mendapat diskon 20%"

.text5.value=val(.text3.text)-val(.text3.text)*0.2

.text6.value=val(.text3.text)*0.2

.check1.enabled=.f.

.check2.enabled=.f.

Endwith



Mulai

with thisform

.text1.value=""

.text2.value=""

.text3.value=""

.text4.value=""

.text5.value=""

.text6.value=""

Endwith



Selesai

thisform.release()


Tugas 2 Struktur Data

IF ELSE
var
a:integer;
begin
write('Berapa tinggi badanmu? [cm] ');
readln(a);
if (a>=100) and (a<=150) then
writeln('Anda Pendek')
else
if (a>=151) and (a<=169) then
writeln('Tinggi badan Ideal')
else
if (a>=170) and (a<=200) then
writeln('Anda Tinggi');
readln;
end.

var
a:integer;
begin
write('Berapa kali kamu membolos? ');
readln(a);
if a>=5 then
writeln('Kamu tidak boleh mengikuti ujian')
else
writeln('Silahkan persiapkan diri untuk ujian');
readln;
end.

var
a:string;
begin
write('Sudahkan anda belajar untuk ujian? [sudah/belum] ');
readln(a);
if a='sudah' then
writeln('segera istirahat')
else
writeln('belajarlah');
readln;
end.

CASE OF
var
a:integer;
begin
write('Tuliskan sebuah angka [1-10] ');
readln(a);
case a of
1:writeln('Satu');
2:writeln('Dua');
3:writeln('Tiga');
4:writeln('Empat');
5:writeln('Lima');
6:writeln('Enam');
7:writeln('Tujuh');
8:writeln('Delapan');
9:writeln('Sembilan');
10:writeln('Sepuluh');
end;
readln;
end.

var
a:integer;
begin
write('Berapa nilai Struktur Datamu?  ');
readln(a);
case a of
90..100:writeln('Baik Sekali');
80..89:writeln('Baik');
70..79:writeln('Cukup');
60..69:writeln('Belajarlah lagi');
0..59:writeln('Kamu tidak sungguh-sungguh');
end;
readln;
end.

var
a:integer;
begin
write('Berapa jam waktu internetmu?  ');
readln(a);
case a of
1:writeln('Tarif 3000');
2:writeln('Tarif 5000');
3:writeln('Tarif 7000');
end;
readln;
end.

FOR TO DO
var
x:integer;
begin
for x:=50 to 60 do
if (x<>51) and (x<>58)  then
writeln(x);
readln;
end.

var
x:integer;
begin
for x:=100 downto 90 do
if (x<>95) and (x<>91)  then
writeln(x);
readln;
end.

var
baris,kolom,jml:integer;
begin
write ('Jumlah Baris : ');
readln(jml);
for baris:=1 to jml do
begin
write ('#': jml);
for kolom := 2 to (2 *baris -1 ) do
begin
write('#');
end;
readln;
end;
end.

REPEAT UNTIL

var
x:integer;
begin
x:=2;
repeat
writeln(x);
x:=x+2;
until x=10;
readln;
end.

var
x:integer;
begin
x:=5;
repeat
writeln(x);
x:=x+5;
until x=30;
readln;
end.

var
x:integer;
begin
x:=10;
repeat
writeln(x);
x:=x+10;
until x>50;
readln;
end.

WHILE DO

var
x:integer;
begin
x:=3;
while(x<=18) do
begin
writeln(x);
x:=x+3;
end;
readln;
end.

var
x:integer;
begin
x:=5;
while(x<=30) do
begin
writeln(x);
x:=x+5;
end;
readln;
end.

var
x:integer;
begin
x:=2;
while(x<=12) do
begin
writeln(x);
x:=x+2;
end;
readln;
end.

Latihan 8 Sistem Basis Data



Text box harga
with thisform
.jumlah.value=val(.lama.value)*val(.harga.value)
Endwith
Diskon Umum
Diskon1
thisform.diskon.value=thisform.jumlah.value * .3
thisform.keterangan.value="Anda Mendapat Diskon"
thisform.bayar.value=thisform.jumlah.value - thisform.diskon.value

Diskon2
thisform.diskon.value=thisform.jumlah.value * .2
thisform.keterangan.value="Anda mendapat Diskon"
thisform.bayar.value=thisform.jumlah.value - thisform.diskon.value
Diskon3
thisform.diskon.value=thisform.jumlah.value * .1
thisform.keterangan.value="Anda Mendapat Diskon"
thisform.bayar.value=thisform.jumlah.value - thisform.diskon.value
Diskon4
thisform.diskon.value=thisform.jumlah.value * .0
thisform.keterangan.value="Tidak Dapat Diskon"
thisform.bayar.value=thisform.jumlah.value - thisform.diskon.value
Command Button Clear
thisform.lama.value=""
thisform.harga.value=""
thisform.jumlah.value=""
thisform.keterangan.value=""
thisform.diskon.value=""
thisform.bayar.value=""
thisform.lama.setfocus()
Command Button Selesai
thisform.release()

Hasil Run

Latihan 7 Sistem Basis Data



Command Button Proses
with thisform
                if .text1.value="VIP"
                .text3.value=val(.text2.value)*500000
                else
                if .text1.value="Kelas 1"
                .text3.value=val(.text2.value)*350000
                else
                if .text1.value="Kelas 2"
                .text3.value=val(.text2.value)*250000
                else
                .text3.value=val(.text2.value)*100000
endif
endif
endif

if val(.text2.value)>=10
.text4.value="10%"
.text5.value=val(.text3.text)-(val(.text3.text)*0.1)
else
if val(.text2.value)>=8
.text4.value="5%"
.text5.value=val(.text3.text)-(val(.text3.text)*0.05)
else
.text4.value="0%"
.text5.value=val(.text3.text)
endif
endif
Endwith
Command Button Clear
with thisform
.text1.value=""
.text2.value=""
.text3.value=""
.text4.value=""
.text5.value=""
Endwith
Command Button Exit
thisform.release()
Hasil Run