Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

write a program in c++ to implement stack using functions
in header file stack.h

Answer Posted / jhil

# include<iostream.h>
# include<conio.h>
# define SIZE 20

class stack
{
int a[SIZE];
int top; // Top of Stack
public:
stack();
void push(int);
int pop();
int isempty();
int isfull();
};
stack::stack()
{
top=0; //Initialize Top of Stack
}

int stack::isempty()
{
return (top==0?1:0);
}
int stack::isfull()
{
return (top==SIZE?1:0);
}

void stack::push(int i)
{

if(!isfull())
{
cout<<"Pushing a data "<<i<<endl;
a[top]=i;
top++;
}
else
{
cout<<"Stack overflow error !Possible Data Loss !";
}
}
int stack::pop()
{
if(!isempty())
{
cout<<"Popping "<<a[top-1]<<endl;
return(a[--top]);
}
else
{
cout<<"Stack is empty! What to pop...!";
}
return 0;
}

void main()
{
clrscr();
stack s;

s.push(1);
s.push(2);
s.push(3);

s.pop();
s.pop();

getch();
}

Is This Answer Correct ?    15 Yes 23 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of array in c++?

1153


To which numbering system can the binary number 1101100100111100 be easily converted to?

1057


What are exceptions c++?

1037


What is namespace std; and what is consists of?

1285


What is c++ & why it is used?

1088


Can char be a number c++?

1040


Explain one method to process an entire string as one unit?

1577


What are the types of container classes?

1151


What is an adjust field format flag?

1110


What is abstraction in c++ with example?

1100


Differentiate between late binding and early binding. What are the advantages of early binding?

1025


Write syntax to define friend functions in C++.

1066


If a function doesn’t return a value, how do you declare the function?

1051


What is the difference between while and do while loop?

1148


What is the extraction operator and what does it do?

1081