RUPAK SEARCH ENGINE

Custom Search

example of over-riding member function and implementation of stack

eg of over-riding member function and implementation of stack

#include
using namespace std;
#include
#define MAX 5
class stack
{
protected:
int s[MAX],top;
public:
stack(){top=-1;}
void push(int x)
{s[++top]=x;}
int pop(){return s[top--];}
};
class stack1:public stack
{
public:
void push(int x)
{
if(top==MAX-1)
{
cout<<"stack full";
exit(1);
}
stack::push(x);
}
int pop()
{
if(top==-1)
{
cout<<"\nstack empty";
exit(1);
}
return stack::pop();
}
};
int main()
{
stack1 s;
s.push(11);
s.push(22);
s.push(33);
s.push(44);
s.push(55);
s.push(66);
cout<<"\nThe no. of pop is:"$$s.pop();//put less than sign in place of $$
system("pause");
return 0;
}

No comments:

Post a Comment