Contoh Program C++ (Struktur data :Stack)




bagi yang masih bingung tentang stack atau bagai mana cara menggunakan stack tersebut dalam listing borlan c++

nie w kasih contoh program tentang stack ..



#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>

judul()
{
cout<<"Name :  \nClass : \nNim : "<<endl<<"\n\n";
return 0;
}

main()
{

int plh;
int top=0, i;

int sisa;
char nm[20][20],nim[20][20],kls[20][20];

do{
clrscr();
judul();
cout<<"===================================\n";
cout<<" MENU OPTIONS\n";
cout<<"===================================\n";
cout<<"1.PUSH\n";
cout<<"2.POP\n";
cout<<"3.ISFULL/ISEMPTY\n";
cout<<"4.CLEAR \n";
cout<<"5.VIEW \n";
cout<<"6.EXIT\n";
cout<<"===================================\n";
cout<<"Input Options : "; cin>>plh;
if (plh<=6)
{
switch(plh)
{
case 1:
if(top==10)
{
clrscr();
judul();
cout<<"sory,data is full";
getch();
}
else
{
cout<<"\nInput name : "; gets(nm[top+1]);
cout<<"Input NIM : "; cin>>nim[top+1];
cout<<"Input Class : "; cin>>kls[top+1];

clrscr();
judul();
cout<<"data has been entered";
getch();
top++;
}
break;

case 2:

if(top<1)
{
clrscr();
judul();
cout<<"Data is Empty";
}
else
{
cout<<"\nDeleted data :"<<top<<"\n\n";
cout<<"Name : "<<nm[top]<<endl;
cout<<"NIM : "<<nim[top]<<endl;
cout<<"Class : "<<kls[top]<<endl;
top--;
getch();
clrscr();
judul();
cout<<"data has been Deleted";
}
getch();
break;

case 3:
if(top==10)
{
clrscr();
judul();
cout<<"Data has been Full";
}
else if(top>=1)
{
sisa=10-top;
clrscr();
judul();
cout<<"Now Data is still not fully, you have a "<<sisa<<" data space";
}
else if(top==0)
{
clrscr();
judul();
cout<<"Now Data is Empty";
}
getch();
break;

case 4:
clrscr();
judul();
top=0;
cout<<"Data has removed all";
getch();
break;

case 5:
cout<<"NO || NAME || NIM || CLASS ||\n";
if (top==0)
cout<<"Data Is Empty";
else
for(i=1; i<=top; i++)
{
cout<<setiosflags(ios::left)<<setw(8)<<i;
cout<<setiosflags(ios::left)<<setw(17)<<nm[i];
cout<<setiosflags(ios::left)<<setw(17)<<nim[i];
cout<<setiosflags(ios::left)<<setw(10)<<kls[i]<<endl;
}

getch();
break;

case 6:
cout<<"\n\nEXIT.........";
getch();
break;

}
}
else
{
cout<<"incorrect Option , Please Input 1-9";
getch();
}
}while(plh!=6);
}
 
Klo Ada yang Bingung tinggal comment ja yah...

GOOD LUCK..
 

3 comments:

  1. judul dari program tersebut apa bro???

    ReplyDelete
  2. maaf kaka saya masih blm paham
    cara pengoperasiannya gmna ya ? setelah di runing ? bisa minta alamat emailnya ?

    ReplyDelete