plz i cant't correct the errors ..
can any one correct this

#include<iostream.h>
#define size 100
struct stack {
int item [size];
int top=0 ;
};
class m{
bool isempty(stack s)
{
	if (s.top==-1)
		return true ;
	else return false ;}
	bool isfull(stack s);
}
	return (s.top==size-1);}
int count (stack s){
	return (s.top+1);
}
void traverse (stack *p){
	for(int i=0;i<=top+1;i++)
		cout<<p->item[i];}
void push(stack s){
	int x;
	if(isfull(s))
		cout<<"OVERFLOw:";
	else {
		s.top++;
		s.item[top]=x;
		cout<<p->item[top];
}}
void pop(stack s){
	int x;
	if(isempty(s))
		cout<<"UNDERFLOW:";
	else {
		s.top--;
		cout<< p->item[top];
}}
};
void main()
{int x;
cout<<":Push element";
cin>>x;
	m cc;
	cc.push(x);
	cc.pop();
}}

Recommended Answers

All 3 Replies

What are the errors you are getting?

C:\Users\usa\Desktop\data\stackarrayaaa.cpp(36) : error C2039: 'push' : is not a member of 'm'

C:\Users\usa\Desktop\data\stackarrayaaa.cpp(16) : error C2447: missing function header (old-style formal list?)
C:\Users\usa\Desktop\data\stackarrayaaa.cpp(20) : error C2065: 'top' : undeclared identifier
C:\Users\usa\Desktop\data\stackarrayaaa.cpp(24) : error C2065: 'isfull' : undeclared identifier
C:\Users\usa\Desktop\data\stackarrayaaa.cpp(27) : error C2039: 'top' : is not a member of 'stack'

C:\Users\usa\Desktop\data\stackarrayaaa.cpp(5) : error C2252: 'top' : pure specifier can only be specified for functions

this code is apply put with error result ...

#include <iostream.h>

 int const STACKSIZE =10;

class stack1
{ private:
	int Top;
    int Stack[STACKSIZE];
    int item;

public:	
	stack1 () {Top = -1;}  // constructor, which automatically executes when object of the class will be created

	void Push()
		{int item;
	cout<<":::";
	cin>>item;
	if (IsFull())
		cout<<"NO";
	else {
		Stack[++Top] = item;}
		}

	void Pop( )
		{if (IsEmpty())
		cout<<"UNDER";
	else {
		Stack[Top--];
	}
		}

	bool IsEmpty( )
		{ if(Top == -1 ) return true; 
	else return false; }
		
	bool IsFull( )
		{ if(Top == STACKSIZE-1 ) return true;
	else return false; }

	void Traverse( )
		{ int TopTemp = Top;
			do{
				cout<<Stack[TopTemp--];
			} 
			while(TopTemp>= 0);
		}
}; //  end of the class


  
  
  
int main( )
{ 
	stack1  ms;  // Creation of an object
		 
            ms.Push();
			 ms.Pop();
			  ms.Traverse();

		 
     return 0;
}
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.