Kamis, 17 Juli 2014

Contoh Program Double Linked List (Antrian Bank) C++


SOURCE CODE:
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>


void nasabah();
void password();
void teller();
void buat_baru();
void no_antrian();
void panggil();
void tampil();



struct Antrian
{
    char nama [20];
    struct Antrian *kiri, *kanan;
} *baru, *awal=NULL, *akhir=NULL,*hapus,*bantu;

void main()
{int pil;
   do
   {
       clrscr();
      cout<<"=========================="<<endl;
        cout<<"   MENU ANTRIAN BANK"<<endl;
        cout<<"=========================="<<endl;
        cout<<"1. Nasabah"<<endl;
        cout<<"2. Teller "<<endl;
        cout<<"3. Selesai"<<endl;
        cout<<"Pilihan Anda : ";
        cin>>pil;
    if(pil==3)
{ cout << "terima kasih";
break;
}
switch(pil)
{
case 1: nasabah();
break;
case 2:teller();
break;}
}while(pil!=3);
}

void nasabah()
{int piln;
    do
    {
        clrscr();
        cout<<"=========================="<<endl;
        cout<<"   MENU NASABAH"<<endl;
        cout<<"=========================="<<endl;
        cout<<"1. Ambil Antrian"<<endl;
        cout<<"2. Tampilkan Antrian"<<endl;
        cout<<"3. Selesai"<<endl;
        cout<<"Pilihan Anda : ";
        cin>>piln;
        if(piln==3)
{ cout << "terima kasih\n" ;
break;
}
switch(piln)
{
case 1:no_antrian();
break;
case 2: tampil();
break;

}getch();
} while(piln !=3);
getch();
}

void password()
{
char admin[20], id[10], paswod[3]="p69";
{
clrscr();

atas:
clrscr();
cout << "\t\t+===============================================+\n";
cout << "\t\t| S E L A M A T D A T A N G |\n";
cout << "\t\t| jika anda admin dari teller |\n";
cout << "\t\t|Silahkan masukkan User Name & 3 digit Password |\n";
cout << "\t\t+===============================================+\n";
cout << "\t\t UserName : " ; gets(admin);
cout << "\t\t No. Identitas : "; gets(id);
cout << "\t\t Password : "; gets(paswod);
cout << "\n\t\t+=============================================+\n";
if (strcmp(paswod,"h1")==0)
{
cout << "\n\n\t\t Anda Masuk Sebagai TEllER\n";
cout << "\t\t User :" << admin << "\n";
cout << "\t\t No. Identitas : " << id << "\n";
cout << "\n\n\t\tTekan Sembarang tombol untuk ke menu teller..!";
goto bawah;
}
else
{
cout << "\t\t\tmaaf password salah!!!\n" ;
cout << "\t\tketik sembarang tombol untuk kembali ke menu..... ";
getch ();
goto atas;

}
bawah:
getch();
}
}

void teller()
{int pilt;
password();
    do
    {
        clrscr();
        cout<<"=========================="<<endl;
        cout<<"   MENU TELLER"<<endl;
        cout<<"=========================="<<endl;
        cout<<"1. Panggil"<<endl;
        cout<<"2. Tampilkan Antrian"<<endl;
        cout<<"3. Selesai"<<endl;
        cout<<"Pilihan Anda : ";
        cin>>pilt;
if(pilt==3)
{ cout << "terima kasih\n";

break;
}

switch(pilt)
{
case 1: panggil();
break;
case 2: tampil();
break;
}getch();
} while(pilt !=3);
}
void buat_baru()
{
    baru=(Antrian*)malloc(sizeof(struct Antrian));


    cout<<"input nama  : ";cin>>baru->nama;

    baru->kiri=NULL;
    baru->kanan=NULL;
}

void no_antrian()
{
    buat_baru();
    if(awal==NULL)
    {
        awal=baru;
        akhir=baru;
    }
    else
    {
        akhir->kanan=baru;
        baru->kiri=akhir;
        akhir=baru;
    }
    cout<<endl<<endl;
    tampil();
}

void panggil()
{
    //cout<<"antrian -> "<<awal->nama<<endl;
    if (awal==NULL)
        cout<<"Kosong..!"<<endl;
    else if (awal->kanan==NULL)
    { cout<<"antrian -> "<<awal->nama<<endl;
      hapus=awal;
      awal=NULL;
      akhir=NULL;
      free(hapus);
    }
    else
    {   cout<<"antrian -> "<<awal->nama<<endl;
        hapus=awal;
        awal=hapus->kanan;
        awal->kiri=NULL;
        free(hapus);
    }
    cout<<"selanjutnya -> ";
    if(awal==NULL){
    cout<<"tidak ada";
    }else{
    cout<<awal->nama<<endl;}
    cout<<endl;

    getch();
}

void tampil()
{
     int a=0;
     if (awal==NULL)
          cout<<"Kosong";
     else
     {
         bantu=awal;
         while(bantu!=NULL)
         {
            cout<<"Nama : "<<bantu->nama;
            bantu=bantu->kanan;
            a=a+1;
         cout<<"  antrian ke --> "<<a<<endl;
         }

     }
     getch();
}

1 komentar: