Jawaban UTS Pemrograman Berorientasi Obyek
Soal 1
Buatlah program penghitungan gaji dengan input berupa: Golongan (1/2/3/4), Ada Istri/Suami (Y/T), Jumlah Anak, Jumlah Jam Lembur. Sedangkan Outputnya: Gaji Pokok, Tunjangan fungsional, Tunjangan Suami/Istri, Tunjangan Anak, Tunjangan Beras, Insentif Lembur, Total Gaji. Beberapa ketentua sebagai berikut:
a. 1 2 3 4 5 6 7 8 9 10
b. 5 6 7 8 9 10 11 12 13 14
c. -5 -6 -7 -8 -9 -10 -11 -12 -13 -14
d. 1 2 3 4 1 2 3 4 1 2
e.. 3 6 9 12 15 18 21 24 27 30
f. 30 27 24 21 18 15 12 9 6 3
g. -8 -6 -4 -2 0 2 4 6 8 10
h. 1 3 6 10 15 21 28 36 45 55
Jawab:
Buatlah program penghitungan gaji dengan input berupa: Golongan (1/2/3/4), Ada Istri/Suami (Y/T), Jumlah Anak, Jumlah Jam Lembur. Sedangkan Outputnya: Gaji Pokok, Tunjangan fungsional, Tunjangan Suami/Istri, Tunjangan Anak, Tunjangan Beras, Insentif Lembur, Total Gaji. Beberapa ketentua sebagai berikut:
- Gaji Pokok, Tunjangan Fungsional berdasarkan Golongan
Golongan | Gaji Pokok | Tunjangan Fungsional |
1 | 1000000 | 200000 |
2 | 1500000 | 350000 |
3 | 2500000 | 500000 |
4 | 4500000 | 800000 |
- Jika ada Istri/Suami maka Tunjangan Suami/Istri : 500000
- Tunjangan Anak berdasarkan Jumlah anak
Jumlah Anak | Gaji Pokok |
1 | 200000 |
2 | 500000 |
>= 3 | 800000 |
- Tunjangan Beras : 200000
- Insentif lembur dihitung berdasarkan Jumlah Jam Lembur * 20000
- Total Gaji dihitung berdasarkan jumlahan Gaji Pokok, Tunjangan fungsional, Tunjangan Suami/Istri, Tunjangan Anak, dan Insentif Lembur. Contoh Tampilan Sebagai berikut:
Jawaban
01
procedure
TForm1
.
Button1Click(Sender: TObject);
02
Var
G, JA, JJL :
integer
;
03
AIS :
String
;
04
GP, TF, TSI, TA, TB, IL, TG :
real
;
05
begin
06
G:= strtoint(edit1
.
text);
07
AIS:= edit2
.
Text;
08
JA:= strtoint(edit3
.
text);
09
JJL:=strtoint(edit4
.
text);
10
if
G=
1
then
11
begin
12
GP:=
1000000
;
13
TF:=
200000
;
14
end
15
else
if
G=
2
then
16
begin
17
GP:=
1500000
;
18
TF:=
350000
;
19
end
20
else
if
G=
3
then
21
begin
22
GP:=
2500000
;
23
TF:=
500000
;
24
end
25
else
26
Begin
27
GP:=
4500000
;
28
TF:=
800000
;
29
End
;
30
31
If
AIS =
'Y'
then
32
TSI :=
500000
33
else
34
TSI :=
0
;
35
36
If
JA =
1
then
37
TA :=
200000
38
else
If
JA =
2
then
39
TA :=
500000
40
else
41
TA :=
800000
;
42
TB :=
200000
;
43
IL := JJL *
20000
;
44
TG := GP+TF+TSI+TA+TB +IL;
45
46
Edit5
.
Text := FloatToStr(GP);
47
Edit6
.
Text := FloatToStr(TF);
48
Edit7
.
Text := FloatToStr(TSI);
49
Edit8
.
Text := FloatToStr(TA);
50
Edit9
.
Text := FloatToStr(TB);
51
Edit10
.
Text := FloatToStr(IL);
52
Edit11
.
Text := FloatToStr(TG);
53
end
;
54
procedure
TForm1
.
Button2Click(Sender: TObject);
55
begin
56
Edit1
.
Text :=
''
;
57
Edit2
.
Text :=
''
;
58
Edit3
.
Text :=
''
;
59
Edit4
.
Text :=
''
;
60
Edit5
.
Text :=
''
;
61
Edit6
.
Text :=
''
;
62
Edit7
.
Text :=
''
;
63
Edit8
.
Text :=
''
;
64
Edit9
.
Text :=
''
;
65
Edit10
.
Text :=
''
;
66
Edit11
.
Text :=
''
;
67
Edit1
.
setfocus;
68
end
;
69
70
procedure
TForm1
.
Button3Click(Sender: TObject);
71
begin
72
Close
73
end
;
01 | procedure TForm1 . Button1Click(Sender: TObject); |
02 | Var G, JA, JJL : integer ; |
03 | AIS : String ; |
04 | GP, TF, TSI, TA, TB, IL, TG : real ; |
05 | begin |
06 | G:= strtoint(edit1 . text); |
07 | AIS:= edit2 . Text; |
08 | JA:= strtoint(edit3 . text); |
09 | JJL:=strtoint(edit4 . text); |
10 | if G= 1 then |
11 | begin |
12 | GP:= 1000000 ; |
13 | TF:= 200000 ; |
14 | end |
15 | else if G= 2 then |
16 | begin |
17 | GP:= 1500000 ; |
18 | TF:= 350000 ; |
19 | end |
20 | else if G= 3 then |
21 | begin |
22 | GP:= 2500000 ; |
23 | TF:= 500000 ; |
24 | end |
25 | else |
26 | Begin |
27 | GP:= 4500000 ; |
28 | TF:= 800000 ; |
29 | End ; |
30 |
31 | If AIS = 'Y' then |
32 | TSI := 500000 |
33 | else |
34 | TSI := 0 ; |
35 |
36 | If JA = 1 then |
37 | TA := 200000 |
38 | else If JA = 2 then |
39 | TA := 500000 |
40 | else |
41 | TA := 800000 ; |
42 | TB := 200000 ; |
43 | IL := JJL * 20000 ; |
44 | TG := GP+TF+TSI+TA+TB +IL; |
45 |
46 | Edit5 . Text := FloatToStr(GP); |
47 | Edit6 . Text := FloatToStr(TF); |
48 | Edit7 . Text := FloatToStr(TSI); |
49 | Edit8 . Text := FloatToStr(TA); |
50 | Edit9 . Text := FloatToStr(TB); |
51 | Edit10 . Text := FloatToStr(IL); |
52 | Edit11 . Text := FloatToStr(TG); |
53 | end ; |
54 | procedure TForm1 . Button2Click(Sender: TObject); |
55 | begin |
56 | Edit1 . Text := '' ; |
57 | Edit2 . Text := '' ; |
58 | Edit3 . Text := '' ; |
59 | Edit4 . Text := '' ; |
60 | Edit5 . Text := '' ; |
61 | Edit6 . Text := '' ; |
62 | Edit7 . Text := '' ; |
63 | Edit8 . Text := '' ; |
64 | Edit9 . Text := '' ; |
65 | Edit10 . Text := '' ; |
66 | Edit11 . Text := '' ; |
67 | Edit1 . setfocus; |
68 | end ; |
69 |
70 | procedure TForm1 . Button3Click(Sender: TObject); |
71 | begin |
72 | Close |
73 | end ; |
Soal 2
Buatlah program yang menampilkan deret pada suatu Listbox sebagai berikut:a. 1 2 3 4 5 6 7 8 9 10
b. 5 6 7 8 9 10 11 12 13 14
c. -5 -6 -7 -8 -9 -10 -11 -12 -13 -14
d. 1 2 3 4 1 2 3 4 1 2
e.. 3 6 9 12 15 18 21 24 27 30
f. 30 27 24 21 18 15 12 9 6 3
g. -8 -6 -4 -2 0 2 4 6 8 10
h. 1 3 6 10 15 21 28 36 45 55
Jawab:
01 | procedure TForm1 . Button1Click(Sender: TObject); |
02 | var i: integer ; |
03 | begin |
04 | Listbox1 . clear; |
05 | For i:= 1 to 10 do |
06 | Listbox1 . Items . Add(inttostr(i)) |
07 | end ; |
08 |
09 | procedure TForm1 . Button2Click(Sender: TObject); |
10 | var i: integer ; |
11 | begin |
12 | Listbox1 . clear; |
13 | For i:= 5 to 14 do |
14 | Listbox1 . Items . Add(inttostr(i)) |
15 | end ; |
16 |
17 | procedure TForm1 . Button3Click(Sender: TObject); |
18 | var i: integer ; |
19 | begin |
20 | Listbox1 . clear; |
21 | For i:= 1 to 10 do |
22 | Listbox1 . Items . Add(inttostr(- 4 -i)) |
23 | end ; |
24 |
25 | procedure TForm1 . Button4Click(Sender: TObject); |
26 | var i: integer ; |
27 | begin |
28 | Listbox1 . clear; |
29 | For i:= 1 to 10 do |
30 | begin |
31 | if i mod 4 <> 0 then |
32 | Listbox1 . Items . Add(inttostr(i mod 4 )) |
33 | else |
34 | Listbox1 . Items . Add(inttostr( 4 )) |
35 | end ; |
36 | end ; |
37 |
38 | procedure TForm1 . Button5Click(Sender: TObject); |
39 | var i: integer ; |
40 | begin |
41 | Listbox1 . clear; |
42 | For i:= 1 to 10 do |
43 | Listbox1 . Items . Add(inttostr(i* 3 )) |
44 | end ; |
45 |
46 | procedure TForm1 . Button6Click(Sender: TObject); |
47 | var i: integer ; |
48 | begin |
49 | Listbox1 . clear; |
50 | For i:= 1 to 10 do |
51 | Listbox1 . Items . Add(inttostr( 33 -i* 3 )) |
52 | end ; |
53 |
54 | procedure TForm1 . Button7Click(Sender: TObject); |
55 | var i: integer ; |
56 | begin |
57 | Listbox1 . clear; |
58 | For i:= 1 to 10 do |
59 | Listbox1 . Items . Add(inttostr(- 10 +i* 2 )) |
60 | end ; |
61 |
62 | procedure TForm1 . Button8Click(Sender: TObject); |
63 | var h,i: integer ; |
64 | begin |
65 | Listbox1 . clear; |
66 | h:= 0 ; |
67 | For i:= 1 to 10 do |
68 | begin |
69 | h := h+i; |
70 | Listbox1 . Items . Add(inttostr(h)) |
71 | end |
72 | end ; |
Komentar
Posting Komentar