You are on page 1of 4

CARLA MAE LACBAYIN

CEIT-03-402P
#include<conio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
class array
//-----------------------------------------------------------------------------------------{
string number[10];
int top;
int max;
char answer;
char stack[15];
public:
array()
//-----------------------------------------------------------------------------------------{
top = -1;
max = 10;
}
void push();
void pop();
void peek();
void displayforpush();
void displayforpop();
void empty();
void again();
void menu();
};
//-----------------------------------------------------------------------------------------void array::menu()
{
char choice;
string n;
cout<<"\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\"<<endl;
cout<<"\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"\t\t%%%%%%%%%%%%%%%PICK A CHOICE%%%%%%%%%%%%%%"<<endl;
cout<<"\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<"\n";
cout<<"\n\t\t\t[S] ADD A ITEM (PUSH)";
cout<<"\n\t\t\t[T] DELETE A ITEM (POP)";
cout<<"\n\t\t\t[A] SEE THE TOP ITEM";
cout<<"\n\t\t\t[C] STACKS EMPTY";
cout<<"\n\t\t\t[K] EXIT\n";
cout<<"\n\t\t\tJUST ENTER YOUR CHOICE : ";
cin>>choice;
//-----------------------------------------------------------------------------------------switch(choice)
{
case 'S':
case 's':cout<<"\n\tENTER YOUR ITEM THAT YOU WANT TO ADD OR PUSH : ";
push();
break;
case 'T':
case 't':pop();
break;
case 'A':
case 'a':peek();
break;
case 'C':
case 'c':empty();
case 'K':
case 'k':cout<<endl<<"BYEBYE. . . . . "<<endl;
exit(0);
default: system("CLS");

cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\"<<endl;
cout<<"\t\t\t%%%%%%You Just Entered Invalid Choice%%%%%%%";
cout<<"\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\t\t\t%%%%%%%%%%%%%%Enter Again%%%%%%%%%%%%%%%%%%%";
cout<<"\t\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
}
menu();
}
//-----------------------------------------------------------------------------------------void array::push()
{
cin>>stack;
if(top==max)
{
cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\"<<endl;
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%OVERFLOW!!!%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
again();
}
else
{
system("cls");
top++;
number[top]=stack;
displayforpush();
}
menu();
}
//-----------------------------------------------------------------------------------------void array::displayforpush()
{
cout<<endl;
if(top != -1)
{
cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\"<<endl;
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%YOUR ITEM LIST%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
cout<<"\n\t\t\t[ Your Item "<<stack<<" was PUSHED ]"<<"\n";
for(int i=top;i>=0;i--)
cout<<"\n\t\t\t"<<"["<<i<<"]"<<"\t"<<"~ <( "<<number[i]<<" )> ~"<<endl;
cout<<" ";
cout<<endl;
}
}
//----------------------------------------------------------------------------------------void array::pop()
{
if(top == -1)
{
cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\"<<endl;
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%UNDERFLOW!!!%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
again();
}
else
{
system("cls");
string n=number[top];
top--;
cout<<endl;
displayforpop();
}
menu();
}

//----------------------------------------------------------------------------------------void array::displayforpop()
{
cout<<endl;
if(top !=-1)
{
cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\"<<endl;
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%YOUR ITEM LIST%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
cout<<"\n\t\t\t[ Your Item "<<stack<<" was POP ]"<<"\n";
for(int i=top;i>=0;i--)
cout<<"\n\t\t\t"<<"["<<i<<"]"<<"\t"<<"* <[ "<<number[i]<<" ]> *"<<endl;
cout<<" ";
cout<<endl;
}
}
//----------------------------------------------------------------------------------------void array::peek()
{
cout<<endl;
if(top == -1)
{
system("cls");
cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%EMPTY STACK%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
again();
}
else
{
system("cls");
cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\"<<endl;
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%YOUR ITEM LIST%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
cout<<"\n\t\t\t[ Your Item "<<stack<<" is PEEK ]"<<"\n";
for(int i=top;i>=0;i--)
cout<<"\n\t\t\t"<<"["<<i<<"]"<<"\t"<<"* <[ "<<number[i]<<" ]> *"<<endl;
cout<<" ";
cout<<endl;
}
}
//---------------------------------------------------------------------------------------void array::empty()
{
while(top!=-1)
{
top--;
}
cout<<"\t\t\t//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\\";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%EMPTY STACK%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\t\\\%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%//"<<endl;
again();
}
//----------------------------------------------------------------------------------------void array::again()
{
char answer;
cout<<"\n\n\t\tTRY ONCE MORE?[Y/N] :\t";
cin>>answer;
switch(answer)
{
case 'Y':

case 'y':menu();
break;
case 'N':
case 'n':menu();
default:cout<<"\n\t\t Your Input was INVALID!"<<endl;menu();
}
}
void main()
{
void stacks();
cout<<"\t\t//%%%%%%%Hey! This is my Program.%%%%%%%%%%%\\";
cout<<"\n\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t%%%%%%%%%%%%%%CARLA MAE LACBAYIN%%%%%%%%%%%%";
cout<<"\n\t\t%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%";
cout<<"\n\t\t\\%%%%%%%%%%%%%%%%%%%%%%%%CEIT-03-402P%%%%%%//"<<endl;
cout<<"\n";
array a;
a.menu();
}

You might also like