Senin, 29 April 2013
Contoh Program Stack
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
main()
{
int plh;
int top=-1, i;
int nim[20], kls[20]; // variabel strack
char nm[20][20]; // variabel strack
do{
clrscr();
cout<<"===================================\n";
cout<<" MENU PILIHAN\n";
cout<<"===================================\n";
cout<<"1.PUSH\n";
cout<<"2.POP\n";
cout<<"3.ISFULL\n";
cout<<"4.ISEMPTY\n";
cout<<"5.CLEAR\n";
cout<<"6.VIEW\n";
cout<<"7.EXIT\n";
cout<<"===================================\n";
cout<<"Masukan pilihan : "; cin>>plh;
switch(plh)
{
case 1: //menu push
if(top==9)
{
clrscr();
cout<<"maaf stack telah penuh";
}
else
{
cout<<"\nMasukan Nama : "; gets(nm[top+1]);
cout<<"Masukan NIM : "; cin>>nim[top+1];
cout<<"Masukan Kelas : "; cin>>kls[top+1];
top++;
}
break;
case 2: //menu pop
if(top<0)
{
clrscr();
cout<<"maaf stack masih kosong";
}
else
{
cout<<"\nData yang dihapus adalah :\n\n";
cout<<"Nama : "<<nm[top]<<endl;
cout<<"NIM : "<<nim[top]<<endl;
cout<<"Kelas : "<<kls[top]<<endl;
top--;
}
getch();
break;
case 3: //menu isfull
if(top==9)
cout<<"Sekarang strack yang ada telah penuh";
else
cout<<"Sekarang strack yang ada masih belum penuh";
getch();
break;
case 4: //menu isempty
if(top==-1)
cout<<"Sekarang strack kosong";
else
cout<<"Sekarang strack tidak kosong";
getch();
break;
case 5: //menu clear
top=-1;
cout<<"strack telah dihapus semua";
getch();
break;
case 6: //menu view
cout<<"NO NAMA NIM KELAS\n";
for(i=top; i>=0; i--)
{
cout<<setiosflags(ios::left)<<setw(5)<<i;
cout<<setiosflags(ios::left)<<setw(8)<<nm[i];
cout<<setiosflags(ios::left)<<setw(8)<<nim[i];
cout<<setiosflags(ios::left)<<setw(10)<<kls[i]<<endl;
}
getch();
break;
case 7: //menu exit
cout<<"\n\nEXIT.........";
getch();
break;
}
}while(plh!=7);
}
Langganan:
Posting Komentar (Atom)
Tidak ada komentar:
Posting Komentar