Modul 6
STRUKTUR PERULANGAN (LOOPING)
PRAKTEK PEMROGRAMAN TERSTRUKTUR
A. DASAR TEORI
Array merupakan salah satu tipe data dalam pemrograman terstruktur digunakan untuk melakukan penyimpanan data secara berurutan. Dalam Array data tersimpan dalam sebuah index untuk memudahkan kembali data dalam melakukan pencarian. Berbeda dengan variabel yang hanya dapat menyimpan satu data maka dengan menggunakan array data dapat tersimpan dalam beberapa indeks jumlah data dalam array. Data yang tersimpan dalam array disebut elemen-elemen array dan letak masing-masing data yang terurut ditunjukan dalam sebuah indeks. Array mempuyai batas atas dan bawah dimana data akan tersimpan dalam batas masing-masing dengan tipe data yang sama. Array terdiri dari dimensi yaitu array dimensi satu (one dimention), array dua dimensi (two dimention array), array dimesnsi tiga (three dimention array).
B. PRAKTEK
1. Menggunakan array satu dimensi
Ketikkan Source Code berikut di editor Notepad++
<html>
<font color = "#9932CC">
<font face = "Comic Sans MS">
<font size = "4px">
<body bgcolor = "FFB6C1">
<head>
<title>Menggunakan Array</title>
</head>
<body>
<?php
#Cara pendeklarasian array pertama
$hobi = array("sepakbola","basket","melukis","membaca");
print("<p>
Hobi Saya:<br>");
print($hobi[3]);
#Cara pendeklarasian array kedua
$nama[] = "Rosita Sosiana";
$nama[] = "Julaiha";
$nama[] = "Budi Sasongko";
$nama[] = "Sarjono";
$nama[] = "Nuri Hadiningsih";
$nama[] = "Dian Atmojo";
print("<p>
nama saya:<br>");
print($nama[4]);
#Cara pendeklarasian array ketiga
$alamat[0] = "Jakarta";
$alamat[5] = "Kebumen";
$alamat[2] = "Surabaya";
$alamat[] = "Solo";
$alamat[] = "Semarang";
$alamat[kampus] = "AMIK PGRI Kebumen";
print("<p>
alamat saya:<br>");
print("$alamat[5] <br>");
print("Saat ini saya sedang kuliah di $alamat[kampus]");
?>
</body>
</html>
1. Menggunakan array satu dimensi
Ketikkan Source Code berikut di editor Notepad++
<html>
<font color = "#9932CC">
<font face = "Comic Sans MS">
<font size = "4px">
<body bgcolor = "FFB6C1">
<head>
<title>Menggunakan Array</title>
</head>
<body>
<?php
#Cara pendeklarasian array pertama
$hobi = array("sepakbola","basket","melukis","membaca");
print("<p>
Hobi Saya:<br>");
print($hobi[3]);
#Cara pendeklarasian array kedua
$nama[] = "Rosita Sosiana";
$nama[] = "Julaiha";
$nama[] = "Budi Sasongko";
$nama[] = "Sarjono";
$nama[] = "Nuri Hadiningsih";
$nama[] = "Dian Atmojo";
print("<p>
nama saya:<br>");
print($nama[4]);
#Cara pendeklarasian array ketiga
$alamat[0] = "Jakarta";
$alamat[5] = "Kebumen";
$alamat[2] = "Surabaya";
$alamat[] = "Solo";
$alamat[] = "Semarang";
$alamat[kampus] = "AMIK PGRI Kebumen";
print("<p>
alamat saya:<br>");
print("$alamat[5] <br>");
print("Saat ini saya sedang kuliah di $alamat[kampus]");
?>
</body>
</html>
2. Menggunakan Array Multidimensi
Ketikkan Source Code berikut di editor Notepad++
<html>
<font color = "#9932CC">
<font face = "Comic Sans MS">
<font size = "4px">
<body bgcolor = "FFB6C1">
<head>
<title>Array Multidimensi</title>
</head>
<body>
<?php
$nama = array(
"jabatan"=>array("Direktur","Personalia","Sales Accounting","Akunting"),
"pt"=>array("Solusindo Software Utama","AMIK Jaya Software","Web Desain
solusindo"),
"kota"=>array("Jakarta","Yogyakarta","Surabaya","Kebumen"));
print("Saya berasal dari ".$nama[kota][3]."
dan sekarang saya bekerja di ".$nama[pt][1]);
?>
</body>
</html>
<font color = "#9932CC">
<font face = "Comic Sans MS">
<font size = "4px">
<body bgcolor = "FFB6C1">
<head>
<title>Array Multidimensi</title>
</head>
<body>
<?php
$nama = array(
"jabatan"=>array("Direktur","Personalia","Sales Accounting","Akunting"),
"pt"=>array("Solusindo Software Utama","AMIK Jaya Software","Web Desain
solusindo"),
"kota"=>array("Jakarta","Yogyakarta","Surabaya","Kebumen"));
print("Saya berasal dari ".$nama[kota][3]."
dan sekarang saya bekerja di ".$nama[pt][1]);
?>
</body>
</html>
1.Buatlah Program menggunakan Array 1 dimensi untuk mengakses data-data mahasiswa
Ketikkan Source Code berikut di editor Notepad++
<html>
<font color = "#9932CC">
<font face = "Comic Sans MS">
<font size = "4px">
<body bgcolor = "FFB6C1">
<head>
<title>Modul 6 </title>
<link href='/style.css' rel='stylesheet' type='text/css'/>
<script src='/script.js' type='text/javascript'></script>
</head>
<body onload="document.body.style.backgroundColor=bg">
<div id="judul">
Tugas Array 1 dimensi</div>
<div id="isi">
<?php
$nim = Array("13MI0001","13MI0002","13MI0003","13MI0004","13MI0005","13MI0006","13MI0007","13MI0008","13MI0010","13MI0011","13MI0012","13MI0013","13MI0014","13MI0015","13MI0016","13MI0017","13MI0018","13MI0019","13MI0020","13MI0021","13MI0023","13MI0024","13MI0025","13MI0026","13MI0027","13MI0028",);
$nama = Array("Adi Nurcahyo","Ahmad Amirudin","Ahmad Shoerudin","Anang Sulistyo Fadli","Bayu Aditya","Defi Dyah Anggraeni","Destantia Permatasari","Fitriyani","Imam Ihsan Permana","Inarotul Ainiyah","Insanatun Fadillah","Laila Kurniati Rahma","Luvi Ikhtiyarini","Ninik Fitriyani","Nurhalimah","Nuri Hadiningsih","Oki Satria Setiawan","Rizki Arie Putra","Samsul Ma'arif","Sari Setianingtyas","Siti Khadikotun Sururiah","Solikhatun","Supriyani","Tita Isrofi","Titis Rachmatika","Arif Rahman");
print ("<table width=49% align=center border=1 cellspacing=0 style=float:left;>
<tr><th>NIM</th><th>Nama</th></tr>
");
for ($data = 0; $data <= 12; $data++) {
print("
<tr><td>$nim[$data]</td><td>$nama[$data]</td></tr>
");
}
print ("</table>
");
print ("<table width=49% align=center border=1 cellspacing=0 style=float:right;>
<tr><th>NIM</th><th>Nama</th></tr>
");
for ($data = 13; $data <= 25; $data++) {
print("
<tr><td>$nim[$data]</td><td>$nama[$data]</td></tr>
");
}
print ("</table>
");
?>
</div>
</body>
</html>
Hasilnya :
2. Buatlah program menggunakan Array multidimensi dalam transaksi pembelian barang
Ketikkan Source Code berikut di editor Notepad++
<html>
<font color = "#9932CC">
<font face = "Comic Sans MS">
<font size = "4px">
<body bgcolor = "FFB6C1">
<head>
<title>Modul 6</title>
<link href='/style.css' rel='stylesheet' type='text/css'/>
<script src='/script.js' type='text/javascript'></script>
</head>
<body onload="document.body.style.backgroundColor=bg">
<div id="judul">
Tugas array multidimensi</div>
<div id="isi">
<div style="width:32%;margin:0 auto;">
<?php
$perlengkapan = Array("sabunmandi"=>Array("Gift","Harmoni","Lifeboy","Nuvo"),"sampo"=>Array("Sunsilk","Clear","Pantene","Lifeboy Shampo"),"deterjen"=>Array("Daia","Rinso","Soklin","Boom","B-39","Bunga"),"pewangi"=>Array("Downy","Soklin Pewangi"),"sabuncuci"=>Array("Sunlight"));
$peralatan = Array("alatdapur"=>Array("Kompor","Panci","Kwali","Oven"),"alatmakan"=>Array("Sendok","Garpu","Piring","Mangkok","Gelas"),"alatkebersihan"=>Array("Sapu","Kain Lap","Tempat Sampah"),"alatkebun"=>Array("Cangkul","Sekop"));
print("Daftar Belanja:<ol style=margin:0 auto;>
<li>Perlengkapan<ul>
<li>".$perlengkapan['sabunmandi'][2]."<span style=float:right;>(5)</span></li>
<li>".$perlengkapan['sampo'][0]."<span style=float:right;>(2)</span></li>
<li>".$perlengkapan['sampo'][2]."<span style=float:right;>(2)</span></li>
<li>".$perlengkapan['deterjen'][2]."<span style=float:right;>(3)</span></li>
<li>".$perlengkapan['pewangi'][0]."<span style=float:right;>(6)</span></li>
<li>".$perlengkapan['sabuncuci'][0]."<span style=float:right;>(5)</span></li>
</ul>
</li>
<li>Peralatan<ul>
<li>".$peralatan['alatdapur'][0]."<span style=float:right;>(1)</span></li>
<li>".$peralatan['alatdapur'][3]."<span style=float:right;>(1)</span></li>
<li>".$peralatan['alatmakan'][0]."<span style=float:right;>(36)</span></li>
<li>".$peralatan['alatmakan'][2]."<span style=float:right;>(12)</span></li>
<li>".$peralatan['alatkebersihan'][1]."<span style=float:right;>(2)</span></li>
<li>".$peralatan['alatkebun'][1]."<span style=float:right;>(1)</span></li>
</ul>
</li>
</ol>
");
?>
</div>
</div>
</body>
</html>
<font color = "#9932CC">
<font face = "Comic Sans MS">
<font size = "4px">
<body bgcolor = "FFB6C1">
<head>
<title>Modul 6</title>
<link href='/style.css' rel='stylesheet' type='text/css'/>
<script src='/script.js' type='text/javascript'></script>
</head>
<body onload="document.body.style.backgroundColor=bg">
<div id="judul">
Tugas array multidimensi</div>
<div id="isi">
<div style="width:32%;margin:0 auto;">
<?php
$perlengkapan = Array("sabunmandi"=>Array("Gift","Harmoni","Lifeboy","Nuvo"),"sampo"=>Array("Sunsilk","Clear","Pantene","Lifeboy Shampo"),"deterjen"=>Array("Daia","Rinso","Soklin","Boom","B-39","Bunga"),"pewangi"=>Array("Downy","Soklin Pewangi"),"sabuncuci"=>Array("Sunlight"));
$peralatan = Array("alatdapur"=>Array("Kompor","Panci","Kwali","Oven"),"alatmakan"=>Array("Sendok","Garpu","Piring","Mangkok","Gelas"),"alatkebersihan"=>Array("Sapu","Kain Lap","Tempat Sampah"),"alatkebun"=>Array("Cangkul","Sekop"));
print("Daftar Belanja:<ol style=margin:0 auto;>
<li>Perlengkapan<ul>
<li>".$perlengkapan['sabunmandi'][2]."<span style=float:right;>(5)</span></li>
<li>".$perlengkapan['sampo'][0]."<span style=float:right;>(2)</span></li>
<li>".$perlengkapan['sampo'][2]."<span style=float:right;>(2)</span></li>
<li>".$perlengkapan['deterjen'][2]."<span style=float:right;>(3)</span></li>
<li>".$perlengkapan['pewangi'][0]."<span style=float:right;>(6)</span></li>
<li>".$perlengkapan['sabuncuci'][0]."<span style=float:right;>(5)</span></li>
</ul>
</li>
<li>Peralatan<ul>
<li>".$peralatan['alatdapur'][0]."<span style=float:right;>(1)</span></li>
<li>".$peralatan['alatdapur'][3]."<span style=float:right;>(1)</span></li>
<li>".$peralatan['alatmakan'][0]."<span style=float:right;>(36)</span></li>
<li>".$peralatan['alatmakan'][2]."<span style=float:right;>(12)</span></li>
<li>".$peralatan['alatkebersihan'][1]."<span style=float:right;>(2)</span></li>
<li>".$peralatan['alatkebun'][1]."<span style=float:right;>(1)</span></li>
</ul>
</li>
</ol>
");
?>
</div>
</div>
</body>
</html>
Hasilnya :
0 Response to " "
Posting Komentar