Pages

E-mail us at prgms4starters@gmail.com for any queries or to share your programs. Please mention the program definition in the subject line.

In case you need help in finishing a program, do mention "incomplete pgm" in the subject line. Our team of experts will do their best to help you.

Click the link to follow this page for updates and reminders: FOLLOW THIS SITE

You can also visit our Facebook page by clicking HERE

**don't forget to participate in the polls at the bottom of the page

Tuesday, November 9, 2010

Implementation of stack using operator overloading

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

using namespace std;
int s[100];

class stackk
{
public:
int top;
stackk():top(-1)
{}

void operator +(int d)
{
top++;
s[top]=d;
cout<<"\n data added is"<<s[top];


}
void operator --()
{
top--;
}
void operator ++()
{
int a=top;
while(a>=0)
{
cout<<s[a];
a--;
}
}

};
int main()
{
system("cls");
stackk s1;
int data,ch,f=1;
while(f==1)
{
cout<<"\n 1.push \n2.pop \n 3.display";
cout<<"\n enter your choice";
cin>>ch;
switch(ch)
{
case 1:
cout<<"\n enter the data to push";
cin>>data;
s1+data;
break;
case 2:
--s1;
break;
case 3:
++s1;
break;
case 4:return 0;
break;
}
cout<<"\n press 1 to conitnue";
cin>>f;
}
return 1;
}

1 comment:

Anonymous said...

tell the output of his programm

Post a Comment

We have noticed that 20% of our visitors are still using internet explorer. For a better and faster surfing experience we recommend that you switch to either Google Chrome or Mozilla Firefox. We cannot provide you the downloads but here are the links to sites where you can download them from

Google Chrome - click here to go to site

Mozilla Firefox - click here to go to site

Where are you from

Do you think this site was helpful

Should we put up more C or C++ programs