Berikut di bawah ini merupakan program C++ SWITCH CASE yang di compile dengan compiler MICRSOFT VISUAL C++ 2008 EXPRESS EDITION :
# include <iostream>
# include <iostream>
using namespace std ;
int main ()
{
char pilihan ;
cout << " Main Menu " ; cout << endl << endl << endl ;
cout << " 1. Program Perkalian Matriks " ; cout << endl << endl ;
cout << " 2. Program Rata-Rata Dengan Variabel Inputan Array " ; cout << endl << endl ;
cout << " Masukkan pilihan anda : " ;
cin >> pilihan ;
switch ( pilihan ) {
case '1' :
int o , p , q , r , s , t , u , matriks1 [5] [5] , matriks2 [5] [5] , matriks3 [10] [10] ;
cout << endl ;
cout << " Matriks Ke-1 " ;
cout << endl << endl ;
cout << " Masukkan Jumlah Baris = " ;
cin >> o ;
cout << " Masukkan Jumlah Kolom = " ;
cin >> p ;
cout << endl ;
cout << " Inputkan Data ? " ;
cout << endl ;
for ( q = 0 ; q < o ; q++ )
for ( r = 0 ; r < p ; r++ ) {
cout << " Data [ " << ( q + 1 ) << " , " << ( r + 1 ) << " ] = " ;
cin >> matriks1 [q] [r] ;
}
cout << endl ;
cout << " Matriks Ke-1 " ;
cout << endl ;
for ( q = 0 ; q < o ; q++ ) {
for ( r = 0 ; r < p ; r++ ) {
cout << matriks1 [q] [r] << " " ; }
cout << endl ;
cout << endl ;
}
cout << " Matriks Ke-2 " ;
cout << endl << endl ;
cout << " Jumlah Baris = " << o << endl ;
cout << " Jumlah Kolom = " ;
cin >> s ;
cout << endl ;
cout << " Inputkan Data ? " ;
cout << endl ;
for ( q = 0 ; q < o ; q++ )
for ( r = 0 ; r < s ; r++ ) {
cout << " Data [ " << ( q + 1 ) << " , " << ( r + 1 ) << " ] = " ;
cin >> matriks2 [q] [r] ; }
cout << endl ;
cout << " Matriks Ke-2 " ;
cout << endl ;
for ( q = 0 ; q < o ; q++ ) {
for ( r = 0 ; r < s ; r++ ) {
cout << matriks2 [q] [r] << " " ;
}
cout << endl ;
cout << endl ;
}
for ( q = 0 ; q < p ; q++ ) {
for ( r = 0 ; r < s ; r++ ) {
matriks3 [q] [r] = 0 ;
for ( t = 0 ; t < o ; t++ ) {
matriks3 [q] [r] = matriks3 [q] [r] + ( matriks1 [q] [t] * matriks2 [t] [r] ) ; }
}
}
cout << endl ;
cout << " Hasil Kali Matriks Ke-1 Dengan Matriks Ke-2 " ;
cout << endl ;
cout << endl ;
for ( q = 0 ; q < p ; q++ ) {
for ( r = 0 ; r < s ; r++ ) {
cout << matriks3 [q] [r] << " " ;
}
cout << endl ;
cout << endl ;
}
break ;
case '2' :
float a [5] , jumlah , rata_rata ;
int j ;
//Memasukkan atau Meng-input nilai ke dalam elemen array
cout << endl ;
cout << " Masukkan Nilai Yang Ingin Dihitung : \n " ;
jumlah = 0 ;
for( j = 0 ; j < 5 ; j++ ) {
cout << endl ;
cout << " A [ " << j << " ] = " ;
cin >> a [j] ;
jumlah = jumlah + a [j] ;
}
//Melakukan Proses perhitungan
rata_rata = jumlah / 5 ;
cout << endl ;
//Menampilkan atau Output Hasil Perhitungan
cout << " Nilai Rata-Rata Dari Data Diatas Adalah = " << rata_rata ;
cout << endl ;
break ;
default : cout << " Anda Salah Memasukkan Pilihan ... !!! " << endl ;
}
return 0 ;
}
Output Program Pilihan 1
Output Program Pilihan 2
Output Program Pilihan 3
Itulah Program C++ SWITCH CASE yang di compile dengan compiler MICRSOFT C++ 2008 EXPRESS EDITION semoga bermanfaat.
0 komentar:
Posting Komentar