Kamis, 21 April 2011

Menghitunng volume dan luas permukaan balok

Menghitunng volume dan luas permukaan balok
Rumus:

Volume: = P*L*T
Luas : = (2*P*L) + (2*L*T) + (2*P*T)
Tempatkan komponen-komponen berikut pada form lalu ubah propertiesnya.
1. Label 1:
Caption : menghitung volume & luas permukaan
Font.style : Bold
Font.size : 16
2. Label 2:
Caption : panjang
3. Label 3 ;
Caption : lebar
4. Label 4:
Caption : tinggi
5. Label 5 :
Caption : volume
6. Label 6 :
Caption : luas permukaan
7. edit1.text, edit2.text, edit3.text, sampai edit5.text (text diisi dengan nilai 0)
8. Buton 1:
Caption : hitung
Event onlick sebagai berikut :
Var p,l,t, volume, luas : integer; //tempatkan variable di atas procedure
Procedur TForm1.Button1 click(sender: object);
Begin
//konversi dari string ke integer
P = StrToInt (Edit1.Text);
L = StrToInt (Edit2.Text);
T = StrToInt (Edit3.Text);
Vol := P*L*T ;
Luas := (2*P*L) + (2*P*T) + (2*L*T)
//konversi dari integer ke string
Edit4.Text := IntToStr(Vol);
5
Edit5.Text := IntToStr(Luas);
end;
9. Image1: untuk menampilkan gambar bertipe MBP atau JPEG (optimal)
Picture : balok.bmp (sebelumnya telah dibuat melalui program PAINT)
Hasil Running :(isikan nilai panjang=10, lebar=18, tinggi=15)
10. hasil:
Volume = 2700
Luas permukaan =1200
Berikut ini adalah contoh yang akan menggunakan nested if dan menggunakan case.
Variable nilai adalah nilai ujian yang akan diperiksa untuk menghasilkan nilai index
Intan:
//Menggunakan Nested If ;
var Nilai : Byte;
begin
if Nilai <35 then begin
Label1. Caption : =’Nilai E’ ;
end else begin
if Nilai <55 then begin
Label1. Caption : =’Nilai D’ ;
end else begin
if Nilai <75 then begin
Label1. Caption := ’Nilai C’ ;
end else begin
if Nilai <85 then begin
Label1. Caption := ’Nilai B’ ;
end else begin
Label1.Caption := ’Nilai A’ ;
end ;
end ;
end ;
end ;
end ;
dince:
//Menggunakan Case.
var Nilai : Byte ;
begin
case Nilai of
6
0..34 : Label1.Caption := ‘Nilai E’ ;
35..54 : Label1.Caption := ‘Nilai D’ ;
55..74 : Label1.Caption := ‘Nilai C’ ;
75..84 : Label1.Caption := ‘Nilai B’ ;
else
Label1.Caption : = ‘Nilai A’ ;
end ;
end ;

Tidak ada komentar:

Posting Komentar