PENYAJIAN ALGORITMA DENGAN FLOWCHART Bentuk Umum Dalam penyajian
PENYAJIAN ALGORITMA DENGAN FLOWCHART
Bentuk Umum
Dalam penyajian algoritma dengan flowchart, setiap simbol diberikan keterangans esuai dengan langkahnya, sebagai contoh
Perhatikan pada proses memasukkan input yang ditandai dengan Dalam flowchart ataupun pseudocode sekalipun, kita diperbolehkan untuk menuliskan perintah input dalam satu baris, dan itu dimengerti oleh pengguna program. Penyajian rangakian permintaan input dalam bentuk tentu akan menyita tempat pada halaman flowchart, sehingga dapat disederhanakan menjadi
Contoh Algoritma Volume. Tabung {Algoritma ini menghitung volume tabung dengan input jari-jari, r, dan tinggi tabung, t. Output Konstanta Phi=3. 14; Variabel r, t, V: bilangan real 1) READ: r 2) READ: t 3) V = Phi*r*r*t 4) WRITE V 5) ENDnya adalah V, sebagai volume tabung }
Penyelesaian Pada bagian deklarasi disebutkan bahwa ada suatu konstanta Phi=3. 14. Inilah yang dimaksud dengan isinsialisasi pada flowchart, berikut ini adalah flowchart dari algoritma Mencari volume tabung.
Bagimana jika algoritma terlalu besar sehingga tidak cukup untuk memnulsikannya dalam satu diagram penuh, kita dapat menggunakan On pgae Connextor sepert contoh berikut. Perhatikan pada flowchart di atas, bahwa dalam satu simbol proses (persegi panjang) bisa berisi lebih dari satu assignment.
ALGORITMA PERCABANGAN DENGAN 1 KONDISI
Kondisi percabangan adalah sebuah struktur dalam algoritma atau pemrograman komputer yang melibatkan suatu kondisi atau persyaratan untuk melakukan operasi-operasi khusus tergantung dari kondisi yang disyaratkan. Sebagai contoh dalam algoritma di atas, Jika omset penjualan >100 juta maka Bonus akan dihitung 1% x Omset. Jual. Bagaimana jika tidak? Contoh pertama ini tidak memberikan solusi atau langkah alternatif untuk menghitung Bonus jika target omset penjualan tidak dipenuhi, hanya saja dengan tidak dipenuhinya kondisi tersebut nilai Bonus akan diberikan nilai Bonus yang ditetapkan di awal yaitu Bonus=0. Kondisi percabangan yang seperti ini disebut dengan kondisi percabangan dengan 1 syarat saja. Kata kunci dari struktur percabangan adalah JIKA (kondisi) MAKA Pernyataan 1 Pernyataan 2 dst
Struktur Percabangan dengan Flowchart Struktur percabangan ditandai dengan tanda belah ketupat. Gambar berikut menggambarkan flowchart untuk satu kondisi syarat saja.
Dari gambar di atas, perhatikan bentuk belah ketupat. Tanda panah dari atas menunjukkan aliran data/informasi yang akan diproses. Jika kondisi dipenuhi (Benar) maka proses berlanjut ke bagian pernyataan struktur. Jika kondisi tidak dipenuhi (maka langsung keluar dari struktur percabangan menuju langkah berikutnya.
ALGORITMA PERCABANGAN DENGAN 2 KONDISI
Pada kegiatan belajar sebelumnya, dibahas percabangan dengan 1 kondisi, yaitu suatu kondisi bersayarat yang memberikan serangkaian langkah jika kondisi dipenuhi, jika tidak dipenuhi maka strutur percabangan tidak akan melakukan apapun untuk kondisi tersebut. Berbeda dengan percabngan dengan 1 kondisi, percabngan 2 kondisi memberikan operasi-operasi khusus pada kondisi tidak dipenuhi. Contoh: Jika Omset. Jual lebih besar dari 100 juta maka hitung besar bonus dengan rumus berikut: Bonus=1% x Omset. Jual Jika tidak, maka hitung besar bonus dengan rumus berikut: Bonus=0;
Atau pada Kasus 2 IF Gaji>5000000 THEN max. Angsuran=40%*Gaji max. Waktu = 12 ELSE max. Angsuran=30%*Gaji max. Waktu = 10
Sehingga dapat dirumuskan bentuk percabangan dengan dua kondisi sebagai berikut JIKA (Kondisi ) MAKA Pernyataan 1 Pernyataan 2 Dst JIKA TIDAK MAKA Pernyataan 1 Pernyataan 2 dst atau dalam Kasus 2 IF (Kondisi ) THEN Pernyataan 1 Pernyataan 2 Dst ELSE Pernyataan 1 Pernyataan 2 dst
Penyajian dengan Flowchart Percabangan 1 Kondisi
Penyajian dengan Flowchart Percabangan 2 Kondisi
Penyajian dengan Flowchart Percabangan lebih 2 Kondisi
- Slides: 19