Following code is implementation of stacks..
but its giving two errors

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

class stack
{
int a[SIZE];
int top;           // Top of Stack
public:
	stack()
	{
		top=0;
	}
	int overflow()
	{
		if(top==SIZE)
		{
		return (1);
		}
		else
		{
		return (0);
		}
	}
	int underflow()
	{
		if (top==0){
		return 1;  }
		else{
		return 0; }
	}
	void push(int i)
	{
		if(!overflow())
		{
		a[top]=i;
		top++;
		}
		else
		{
		cout<<"Overflow";
		}
	}
	int pop()
	{
		if(!underflow())
		{
		return(a[--top]);
		}
		else
		{
		cout<<"Underflow";
		}
return 0;
};




void main()
{
stack new;
int ch=1,num;
while(ch!=0)           [B] ERROR# 1[/B]
{
	cout<<"Stack Operations"<<endl<<"1.Push"<<endl<<"2.Pop"<<endl<<" 3.Underflow"<<endl<<"4.Overflow"<<endl<<" 0.Exit";
	cin>>ch;
	switch(ch)
	{
	case 0:
		exit(1); //Normal Termination of Program
	case 1:
		cout<<"Enter the number to push";
		cin>>num;
		new.push(num);
		break;
	case 2:
		cout<<"Number popped from the stack is: "<<new.pop()<<endl;
		break;
	case 3:
		if(!new.underflow())
		{
		cout<<"Not Empty"<<endl;
		}
		else
		{
		cout<<"Empty";
		}
		break;
	case 4:
		//(new.isfull())?(cout<<"Stack is full."):(cout<<"Stack is not full.");
		break;
	default:
		cout<<"Illegal Option";
	}
}          //end of while
getch();
}                     [B] ERROR# 2[/B]

Error:1--Function containing while are not expanding INLINE
Error:2--Declaration terminated incorrectly..

im not getting it..:(

Recommended Answers

All 4 Replies

sorryy at the Case4:
its not a comment..its an executable line..and it is like that..

(new.isfull())?(cout<<"Stack is full.") cout<<"Stack is not full.");

Following code is implementation of stacks..
but its giving two errors

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

class stack
{
int a[SIZE];
int top;           // Top of Stack
public:
	stack()
	{
		top=0;
	}
	int overflow()
	{
		if(top==SIZE)
		{
		return (1);
		}
		else
		{
		return (0);
		}
	}
	int underflow()
	{
		if (top==0){
		return 1;  }
		else{
		return 0; }
	}
	void push(int i)
	{
		if(!overflow())
		{
		a[top]=i;
		top++;
		}
		else
		{
		cout<<"Overflow";
		}
	}
	int pop()
	{
		if(!underflow())
		{
		return(a[--top]);
		}
		else
		{
		cout<<"Underflow";
		}
return 0;
};




void main()
{
stack new;
int ch=1,num;
while(ch!=0)           [B] ERROR# 1[/B]
{
	cout<<"Stack Operations"<<endl<<"1.Push"<<endl<<"2.Pop"<<endl<<" 3.Underflow"<<endl<<"4.Overflow"<<endl<<" 0.Exit";
	cin>>ch;
	switch(ch)
	{
	case 0:
		exit(1); //Normal Termination of Program
	case 1:
		cout<<"Enter the number to push";
		cin>>num;
		new.push(num);
		break;
	case 2:
		cout<<"Number popped from the stack is: "<<new.pop()<<endl;
		break;
	case 3:
		if(!new.underflow())
		{
		cout<<"Not Empty"<<endl;
		}
		else
		{
		cout<<"Empty";
		}
		break;
	case 4:
		//(new.isfull())?(cout<<"Stack is full."):(cout<<"Stack is not full.");
		break;
	default:
		cout<<"Illegal Option";
	}
}          //end of while
getch();
}                     [B] ERROR# 2[/B]

Error:1--Function containing while are not expanding INLINE
Error:2--Declaration terminated incorrectly..

im not getting it..:(

It looks to me like you are missing an ending bracket for your int pop () function. Try sticking an ending bracket (}) after line 54 and see if that helps.

Still not solving:'(
giving more errors..like..
Structure required on the left side of .
and
statement missing in line#62 and also Function Exit should have a Prototype in line 71....

Still not solving:'(
giving more errors..like..
Structure required on the left side of .
and
statement missing in line#62 and also Function Exit should have a Prototype in line 71....

Look at the code you have posted and notice that the word "new" is in purple. C++ may be interpreting the word "new" as a reserved C++ keyword rather than a variable name. Change the name of your stack variable on line 62 (and anywhere else) to something that is not a C++ keyword and try compiling again. If that doesn't do the job, repost the updated code here, along with the errors and the corresponding line numbers. Please note that when you use the cplusplus code tags, you can't put things in bold and italics as you tried to do in lines 64 and 98. If you want us to look at some particular line, make it a comment rather than bold, then refer to the line in your writeup.

Regarding at least one of your errors (line 71):

exit(1);

try putting this line at the top of the program:

#include <cstdlib>

and see if it goes away.

Also, consider removing the ".h" from line 1

#include <iostream.h>

That probably won't help with the errors, but see this link for for an explanation why to not use <iostream.h> .

http://www.daniweb.com/forums/thread19629.html

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.