Program input dan searching data karyawan C++

Program input dan searching data karyawan C++

Berikut adalah contoh Program sederhana input dan searching data karyawan menggunakan bahasa pemprogramman C++

C++
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
main( )
{

    int n;

    cout<<"________________   KELOMPOK  ________________"<<endl;
    cout<<"________________   Epostlab  ________________"<<endl;
    cout<<"________________   Veebist   ________________"<<endl;
    cout<<"________________   Mangkene  ________________"<<endl<<endl<<endl;

    cout<<"Banyak Data: ";
    cin>>n;

    int jam[n],id[n],pilih,cari,y,holdjam,holdid;
    char nama[n][50],kembali,holdnama[n];
    int terbaik=0;

    cout<<endl<<endl;

    for(int i=0; i<n; i++)
    {
        cout<<"Data "<<(i+1)<<endl;
        cout<<"Masukan Id : ";
        cin>>id[i];
        cout<<"Masukan Nama : ";
        cin>>nama[i];
        cout<<"Masukan Jumlah Jam Kerja : ";
        cin>>jam[i];
        cout<<endl<<endl;
    }

    menu:
    cout<<"1. Cari Data"<<endl;
    cout<<"2. Karyawan Terbaik"<<endl;
    cout<<"3. Keluar"<<endl<<endl;
    cout << "Pilihan : ";
    cin >> pilih;

    cout<<endl<<endl;

    switch(pilih)
    {
    case 1 :
        a:
        cout<<"Masukan ID data : ";
        cin>>cari;
        cout<<endl;

        for(int y=(n-1);y>=0;y--)
        {
            if (cari==id[y])
            {
                cout<<"ID                : "<<id[y]<<endl;
                cout<<"Nama              : "<<nama[y]<<endl;
                cout<<"Jumlah jam kerja  : "<<jam[y]<<endl;
            }
        }
        cout<<endl<<endl;
        cout<<"kembali ke menu[y/n]=";
        cin>>kembali;
        if  (kembali == 'y' ||kembali == 'Y')
        {
            system("cls");
            goto menu;
        }
        else
        {
            system("cls");
            goto a;
        }
        cout<<endl<<endl;
        break;
    case 2 :
        b:
        for(int i=0; i<(n-1); i++)
        {
            for(int i=0; i<(n-1); i++)
            {
                if(jam[i]>jam[i+1])
                {
                    holdjam=jam[i];
                    jam[i]=jam[i+1];
                    jam[i+1]=holdjam;

                    holdid=id[i];
                    id[i]=id[i+1];
                    id[i+1]=holdid;

                    strcpy(holdnama,nama[i]);
                    strcpy(nama[i],nama[i+1]);
                    strcpy(nama[i+1],holdnama);

                }
            }
        }

        for(int i=0; i<n; i++)
        {
            cout<<"ID                : "<<id[i]<<endl;
            cout<<"Nama              : "<<nama[i]<<endl;
            cout<<"Jumlah jam kerja  : "<<jam[i]<<endl<<endl;
        }

        for(int y=(n-1);y>=0;y--)
        {
            if (jam[y]>terbaik)
            {
                terbaik=jam[y];
            }
        }

        for(int y=(n-1);y>=0;y--)
        {
            if (terbaik==jam[y])
            {
                cout<<"Karyawan terbaik  : "<<endl;
                cout<<"ID                : "<<id[y]<<endl;
                cout<<"Nama              : "<<nama[y]<<endl;
                cout<<"Jumlah jam kerja  : "<<jam[y]<<endl;
            }
        }
        cout<<endl<<endl;
        cout<<"kembali ke menu[y/n]=";
        cin>>kembali;
        if  (kembali == 'y'||kembali == 'Y')
        {
            system("cls");
            goto menu;
        }
        else
        {
            system("cls");
            goto b;
        }
        cout<<endl<<endl;
        break;

    case 3:
        exit(0);
        break;

    default :
        cout << "Nomer Salah, Silahkan Masukan Lagi\n";
        break;
    }
}
C++

Semoga bermanfaat

Leave a Reply

Your email address will not be published. Required fields are marked *