//Dickens Fenelon

//Data Structure

//Stack Menu Using classes

 

#include<iostream.h>

#include<stdlib.h>

 

const int stacksize = 0;

 

class stack{

 

private:

     

      int mystack[5];

      int top;

 

public:

 

      void push(int, int&);

      int pop(int&);

      int isempty();

      int isfull(int);

 

};

 

void stack::push(int x, int&){

     

      mystack[top++] = x;

 

}//push function

 

int stack::pop(int &top){

           

              top = top - 1;

              int item = mystack[top];

              return item;

 

}//pop function

 

int stack::isempty(){

                 

              if(top==0) return 1;

              else return 0;

 

}//isempty

 

int stack::isfull(int stacksize){

 

               if(top==stacksize) return 1;

               else return 0;

 

}//isfull

 

void main(){

              stack xstack;

              int x,top; char option;

             

             

              do  { cout<<"Select One Of The Options:"<<endl;

                          cout<<"1-push  2-pop  3-isempty  4-isfull  5-quit:";

                          cin>>option;

                          switch(option){

 

                          case '1':if(xstack.isfull(stacksize))

                                           cout<<"You Can't Push"<<endl;

                                else{cout<<"Enter The Number That Will Be Pushed:";

                                cin>>x;

                                xstack.push(x,top);

                                }//else

                                break;

                               

                          case '2': if(xstack.isempty())

                                            cout<<"you Can't pop"<<endl;

                                else{cout<<"The Number Popped Is:"<<xstack.pop(top);

                                cout<<endl;

                                }//else

                                break;

 

                          case '3': if(xstack.isempty()==1)

                                            cout<<"Stack Is Empty."<<endl;

                                else cout<<"Stack Is Not Empty."<<endl;

                                break;

 

                          case '4': if(xstack.isfull(stacksize)==1)

                                            cout<<"Stack Is Full."<<endl;

                                else cout<<"Stack Is Not Full."<<endl;

                                break;

 

                          case '5':system("cls");

                                cout<<"Thank You For Using Our Menu!"<<endl;

                                break;

                          default:cout<<"Enter Correct Options"<<endl;

                          }//swich

             

              }while(option!='5');

}//main

 

 

 

Hosted by www.Geocities.ws

1