Tampilkan postingan dengan label Pemograman. Tampilkan semua postingan
Tampilkan postingan dengan label Pemograman. Tampilkan semua postingan

Contoh Program C++ Penggunaan Array Penjabaran NIK


Contoh Program C++ Penggunaan Array Penjabaran Nomor Induk Pegawai.
Program penjabaran Nomor Induk Pegawai (NIP) ini menggunakan prinsip dari Array. Array bisa difungsikan sebagai tempat penyimpanan suatu nilai (karakter).
Adapun bentuk dari program penjabaran NIP yang telah Saya buat, yaitu seperti yang tertera di bawah ini.

#include <iostream>
#include <cstring>

using namespace std;

int main()
{
     system ("color F0");
    
     char nama[50];
     char nip[22];
     char tahunlahir1[3];
     char tahunlahir2[3];
     char bulan1[3];
     char bulan2[3];
     char tgl1[3];
     char tgl2[3];
     char tnhpngangktn1[3];
     char tnhpngangktn2[3];
     char tnhpngangktn3[3];
     char tnhpngangktn4[3];
     char blnpngngktn1[3];
     char blnpngngktn2[3];
     char jk[3];
     char norut[3];
    
     cout<< "                      ============<<>><<<=>>><<>>============ "<<endl;
     cout<< "                        Penjabaran Nomor Induk Pegawai (NIP) "<<endl;
     cout<< "                      ============<<>><<<=>>><<>>============ "<<endl;
     cout<<endl;

     cout<<" ==============================================================================="<<endl;
     cout<<" |  Cara Pemakaian Program :                                                   |"<<endl;
     cout<<" |  1. Masukkan Nomor Induk Pegawai Dengan Ketentuan Yang Benar                |"<<endl;
     cout<<" |     contoh  :  19980606 200506 1 002                                        |"<<endl;
     cout<<" |     \"Menggunakan Spasi\"                                                     |"<<endl;
     cout<<" |  2. Masukkan NIP Dengan Benar, Jika Terdapat Kesalahan Pada Pengisian NIP,  |"<<endl;
     cout<<" |     Program Tidak Dapat Mendeteksinya                                       |"<<endl;
     cout<<" ==============================================================================="<<endl;
    
     cout<<endl;
    
     cout<< " ==>>    Masukkan Nama Anda                :";
     cin.getline(nama,50);
    
     cout<<endl;
    
     cout<< " ==>>    Masukkan Nomor Induk Pegawai Anda :";
     cin.getline(nip,22);
    
     if (isdigit(nip[0]))
     {
     cout<<endl;
    
     cout<<" ==============================================================================="<<endl;
     cout<<"   Keterangan Nomor Induk Pegawai Saudara/i  :"<<" "<<nama<<endl;
     cout<<" ==============================================================================="<<endl;
    
     cout<<endl;
    
     switch (nip[2])
     {
           case '1' :
                strcpy( tahunlahir1, "1");
                break;
               
           case '2' :
                strcpy( tahunlahir1, "2" );
                break;
               
           case '3' :
                strcpy( tahunlahir1, "3" );
                break;
    
           case '4' :
                strcpy( tahunlahir1, "4" );
                break;
               
           case '5' :
                strcpy( tahunlahir1, "5" );
                break;
               
           case '6' :
                strcpy( tahunlahir1, "6" );
                break;
               
           case '7' :
                strcpy( tahunlahir1, "7" );
                break;
               
           case '8' :
                strcpy( tahunlahir1, "8" );
                break;
               
           case '9' :
                strcpy( tahunlahir1, "9" );
                break;
               
           default :
                strcpy( tahunlahir1, "0" );
                break;         
     }
    
     switch (nip[3])
     {
           case '1' :
                strcpy( tahunlahir2, "1");
                break;
               
           case '2' :
                strcpy( tahunlahir2, "2" );
                break;
               
           case '3' :
                strcpy( tahunlahir2, "3" );
                break;
    
           case '4' :
                strcpy( tahunlahir2, "4" );
                break;
               
           case '5' :
                strcpy( tahunlahir2, "5" );
                break;
               
           case '6' :
                strcpy( tahunlahir2, "6" );
                break;
               
           case '7' :
                strcpy( tahunlahir2, "7" );
                break;
               
           case '8' :
                strcpy( tahunlahir2, "8" );
                break;
               
           case '9' :
                strcpy( tahunlahir2, "9" );
                break;
               
           default :
                strcpy( tahunlahir2, "0" );               
     }
    
     strcat( tahunlahir1, tahunlahir2);
     cout<<"    1.  Lahir Pada Tahun           = 19"<< tahunlahir1 << endl;
    
     switch (nip[4])
     {
           case '1' :
                strcpy( bulan1, "1");
                break;
    
           case '0' :
                strcpy( bulan1, "0" );
                break;
               
           default :
                strcpy( bulan1, "ERROR" );          
     }
    
     switch (nip[5])
     {   
           case '1' :
                strcpy( bulan2, "1");
                break;
               
           case '2' :
                strcpy( bulan2, "2");
                break;
               
           case '3' :
                strcpy( bulan2, "3");
                break;
               
           case '4' :
                strcpy( bulan2, "4");
                break;
               
           case '5' :
                strcpy( bulan2, "5");
                break;
               
           case '6' :
                strcpy( bulan2, "6");
                break;
               
           case '7' :
                strcpy( bulan2, "7");
                break;
               
           case '8' :
                strcpy( bulan2, "8");
                break;
               
           case '9' :
                strcpy( bulan2, "9");
                break;
          
           default :
                strcpy( bulan2, "0" );              
     }
    
     strcat( bulan1, bulan2);
     cout<<"    2.  Lahir Pada Bulan           ="<<" "<< bulan1 << endl;
      
     switch (nip[6])
     {
           case '1' :
                strcpy( tgl1, "1");
                break;
               
           case '2' :
                strcpy( tgl1, "2" );
                break;
               
           case '3' :
                strcpy( tgl1, "3" );
                break;
    
           case '0' :
                strcpy( tgl1, "0" );
                break;
               
           default :
                strcpy( tgl1, "ERROR" );            
     }
    
     switch (nip[7])
     {
           case '1' :
                strcpy( tgl2, "1");
                break;
               
           case '2' :
                strcpy( tgl2, "2" );
                break;
               
           case '3' :
                strcpy( tgl2, "3" );
                break;
    
           case '4' :
                strcpy( tgl2, "4" );
                break;
               
           case '5' :
                strcpy( tgl2, "5" );
                break;
               
           case '6' :
                strcpy( tgl2, "6" );
                break;
               
           case '7' :
                strcpy( tgl2, "7" );
                break;
               
           case '8' :
                strcpy( tgl2, "8" );
                break;
               
           case '9' :
                strcpy( tgl2, "9" );
                break;
               
           default :
                strcpy( tgl2, "0" );           
     }
    
     strcat( tgl1, tgl2);
     cout<<"    3.  Lahir Pada Tanggal         ="<<" "<< tgl1 << endl;
    
     switch (nip[9])
     {
           case '1' :
                strcpy( tnhpngangktn1, "1");
                break;
               
           case '2' :
                strcpy( tnhpngangktn1, "2" );
                break;
               
           case '3' :
                strcpy( tnhpngangktn1, "3" );
                break;
    
           case '4' :
                strcpy( tnhpngangktn1, "4" );
                break;
               
           case '5' :
                strcpy( tnhpngangktn1, "5" );
                break;
               
           case '6' :
                strcpy( tnhpngangktn1, "6" );
                break;
               
           case '7' :
                strcpy( tnhpngangktn1, "7" );
                break;
               
           case '8' :
                strcpy( tnhpngangktn1, "8" );
                break;
               
           case '9' :
                strcpy( tnhpngangktn1, "9" );
                break;
               
           default :
                strcpy( tnhpngangktn1, "0" );       
     }
    
     switch (nip[10])
     {
           case '1' :
                strcpy( tnhpngangktn2, "1");
                break;
               
           case '2' :
                strcpy( tnhpngangktn2, "2" );
                break;
               
           case '3' :
                strcpy( tnhpngangktn2, "3" );
                break;
    
           case '4' :
                strcpy( tnhpngangktn2, "4" );
                break;
               
           case '5' :
                strcpy( tnhpngangktn2, "5" );
                break;
               
           case '6' :
                strcpy( tnhpngangktn2, "6" );
                break;
               
           case '7' :
                strcpy( tnhpngangktn2, "7" );
                break;
               
           case '8' :
                strcpy( tnhpngangktn2, "8" );
                break;
               
           case '9' :
                strcpy( tnhpngangktn2, "9" );
                break;
               
           default :
                strcpy( tnhpngangktn2, "0" );             
     }
    
     switch (nip[11])
     {
           case '1' :
                strcpy( tnhpngangktn3, "1");
                break;
               
           case '2' :
                strcpy( tnhpngangktn3, "2" );
                break;
               
           case '3' :
                strcpy( tnhpngangktn3, "3" );
                break;
    
           case '4' :
                strcpy( tnhpngangktn3, "4" );
                break;
               
           case '5' :
                strcpy( tnhpngangktn3, "5" );
                break;
               
           case '6' :
                strcpy( tnhpngangktn3, "6" );
                break;
               
           case '7' :
                strcpy( tnhpngangktn3, "7" );
                break;
               
           case '8' :
                strcpy( tnhpngangktn3, "8" );
                break;
               
           case '9' :
                strcpy( tnhpngangktn3, "9" );
                break;
               
           default :
                strcpy( tnhpngangktn3, "0" );             
     }
    
     switch (nip[12])
     {
           case '1' :
                strcpy( tnhpngangktn4, "1");
                break;
               
           case '2' :
                strcpy( tnhpngangktn4, "2" );
                break;
               
           case '3' :
                strcpy( tnhpngangktn4, "3" );
                break;
    
           case '4' :
                strcpy( tnhpngangktn4, "4" );
                break;
               
           case '5' :
                strcpy( tnhpngangktn4, "5" );
                break;
               
           case '6' :
                strcpy( tnhpngangktn4, "6" );
                break;
               
           case '7' :
                strcpy( tnhpngangktn4, "7" );
                break;
               
           case '8' :
                strcpy( tnhpngangktn4, "8" );
                break;
               
           case '9' :
                strcpy( tnhpngangktn4, "9" );
                break;
               
           default :
                strcpy( tnhpngangktn4, "0" );             
     }
    
     cout<<"    4.  Tahun Pengangkatan CPNS    ="<<" "<< tnhpngangktn1 << tnhpngangktn2 << tnhpngangktn3 << tnhpngangktn4 << endl;
    
     switch (nip[13])
     {
           case '1' :
                strcpy( blnpngngktn1, "1");
                break;
    
           case '0' :
                strcpy( blnpngngktn1, "0" );
                break;
               
           default :
                strcpy( blnpngngktn1, "ERROR" );               
     }
    
     switch (nip[14])
     {   
           case '1' :
                strcpy( blnpngngktn2, "1");
                break;
               
           case '2' :
                strcpy( blnpngngktn2, "2");
                break;
               
           case '3' :
                strcpy( blnpngngktn2, "3");
                break;
               
           case '4' :
                strcpy( blnpngngktn2, "4");
                break;
               
           case '5' :
                strcpy( blnpngngktn2, "5");
                break;
               
           case '6' :
                strcpy( blnpngngktn2, "6");
                break;
               
           case '7' :
                strcpy( blnpngngktn2, "7");
                break;
               
           case '8' :
                strcpy( blnpngngktn2, "8");
                break;
               
           case '9' :
                strcpy( blnpngngktn2, "9");
                break;
          
           default :
                strcpy( blnpngngktn2, "0" );              
     }
    
     strcat( blnpngngktn1, blnpngngktn2);
     cout<<"    5.  Bulan Pengangkatan CPNS    ="<<" "<< blnpngngktn1 << endl;
    
     switch (nip[16])
     {   
           case '1' :
                strcpy( jk, "1 (laki-laki)");
                break;
               
           case '2' :
                strcpy( jk, "2 (perempuan)");
                break;
               
           default :
                strcpy( jk, "Tidak Cocok");
     }
          
     cout<<"    6.  Jenis Kelamin              ="<<" "<< jk << endl;
    
     switch (nip[20])
     {   
           case '1' :
                strcpy( norut, "1");
                break;
               
           case '2' :
                strcpy( norut, "2");
                break;
               
           case '3' :
                strcpy( norut, "3");
                break;
               
           case '4' :
                strcpy( norut, "4");
                break;
               
           case '5' :
                strcpy( norut, "5");
                break;
               
           case '6' :
                strcpy( norut, "6");
                break;
               
           case '7' :
                strcpy( norut, "7");
                break;
               
           case '8' :
                strcpy( norut, "8");
                break;
               
           case '9' :
                strcpy( norut, "9");
                break;
          
           default :
                strcpy( norut, "0" );
     }
          
     cout<<"    7.  Nomor Urut CPNS/PNS        ="<<" "<<"00"<< norut << endl;  
     }
    
     else
     {
     cout<<endl;
     cout<< " ==>>    \"NIP Yang Anda Masukkan Salah\""<<endl;
     }
      
     cout<<endl;
  
     cout<<"Created by C++";
    
     cout<<endl;  

     system ("pause");
       
     return 0; 

Gambar. Tampilan Program