Kuis 28 Mei 2012
Disusun oleh :
Novian Adi Prasetyo
201101029
Dosen
Yosef Murya Kusuma Ardhana, S.T
JURUSAN SISTEM INFORMASI
SEKOLAH TINGGI ILMU KOMPUTER (STIKOM)
“YOS SUDARSO”
PURWOKERTO
2012
1. Membuat Program Array Dengan Switch Case
Listing Program :
Output Program :#include <iostream>using namespace std;main (){int i,j,k, pilih;int duadimensi[8][33]={{1,1,0,0,0,0,1,1, 0,0,1,1,1,1,0,0, 0,1,1,1,1,1,1,0, 0,1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,1,0,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,1,1,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,1,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,1,1,1,1,1,1, 0,1,1,0,0,1,0,1,1},{1,1,1,0,0,1,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,0,1,1,1,1},{0,0,1,1,1,1,0,0, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,0,0,1,1,1},{0,0,0,1,1,0,0,0, 0,0,1,1,1,1,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,0,0,0,1,1},};int tigadimensi[4][8][8]={{{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,1,0,0,1,1,1},{0,0,1,1,1,1,0,0},{0,0,0,1,1,0,0,0}},{{0,0,1,1,1,1,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,1,1,1,1,0,0}},{{0,1,1,1,1,1,1,0},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,1,1,1,1,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1}},{{1,1,0,0,0,0,1,1},{1,1,1,0,0,0,1,1},{1,1,1,1,0,0,1,1},{1,1,0,1,0,0,1,1},{1,1,0,0,1,0,1,1},{1,1,0,0,1,1,1,1},{1,1,0,0,0,1,1,1},{1,1,0,0,0,0,1,1}}};cout<<"== Array 2D dan 3D Dengan Switch Case ==\n\n";cout<<"Pilih array untuk menampilkan nama : \n";cout<<"0 = Array 2D \n1 = Array 3D";cout<<"\nPilih : ";cin>>pilih;switch (pilih){case 0:for (i=0;i<8;i++){for (j=0;j<33;j++)if (duadimensi[i][j]==1)cout<<"*";elsecout<<"\x20";cout<<endl;}break;case 1:for (i=0;i<4;i++){for (j=0;j<8;j++){for(k=0;k<8;k++)if(tigadimensi[i][j][k]==1)cout<<"*";elsecout<<"\x20";cout<<endl;}cout<<endl;}break;case 2:break;default:cout<<"salah";}return 0;}
2. Membuat Program Array Dengan While
Listing Program :
Output Program :#include <iostream>using namespace std;main (){int array[1];int pilih,i,j,k;int duadimensi[8][33]={{1,1,0,0,0,0,1,1, 0,0,1,1,1,1,0,0, 0,1,1,1,1,1,1,0, 0,1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,1,0,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,1,1,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,1,0,0,1,1},{1,1,0,0,0,0,1,1, 0,0,0,1,1,0,0,0, 1,1,1,1,1,1,1,1, 0,1,1,0,0,1,0,1,1},{1,1,1,0,0,1,1,1, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,0,1,1,1,1},{0,0,1,1,1,1,0,0, 0,0,0,1,1,0,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,0,0,1,1,1},{0,0,0,1,1,0,0,0, 0,0,1,1,1,1,0,0, 1,1,0,0,0,0,1,1, 0,1,1,0,0,0,0,1,1},};int tigadimensi[4][8][8]={{{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,1,0,0,1,1,1},{0,0,1,1,1,1,0,0},{0,0,0,1,1,0,0,0}},{{0,0,1,1,1,1,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,0,1,1,0,0,0},{0,0,1,1,1,1,0,0}},{{0,1,1,1,1,1,1,0},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1},{1,1,1,1,1,1,1,1},{1,1,0,0,0,0,1,1},{1,1,0,0,0,0,1,1}},{{1,1,0,0,0,0,1,1},{1,1,1,0,0,0,1,1},{1,1,1,1,0,0,1,1},{1,1,0,1,0,0,1,1},{1,1,0,0,1,0,1,1},{1,1,0,0,1,1,1,1},{1,1,0,0,0,1,1,1},{1,1,0,0,0,0,1,1}}};array[0]=duadimensi[8][33];array[1]=tigadimensi[4][8][8];while (1){cout<<"== Array 2D dan 3D Dengan While ==\n\n";cout<<"Pilih array untuk menampilkan nama : \n";cout<<"0 = Array 2D \n1 = Array 3D";cout<<"\nPilih : ";cin>>pilih;if((pilih==0))for (i=0;i<8;i++){for (j=0;j<33;j++)if (duadimensi[i][j]==1)cout<<"*";elsecout<<"\x20";cout<<endl;}if((pilih==1))for (i=0;i<4;i++){for (j=0;j<8;j++){for(k=0;k<8;k++)if(tigadimensi[i][j][k]==1)cout<<"*";elsecout<<"\x20";cout<<endl;}cout<<endl;}break;}return 0;}
Tidak ada komentar:
Posting Komentar