well first this:
Code:
stack(void);/*initialize the stack*/
Should be
Code:
Stack(void);/*initialize the stack*/ //must have big S
You will have to rewrite this:
Code:
Stack::Stack()
{
count=0; /*initialize the top of the stack*/
void Stack::push(const int item)
{
count++;
data[count]=item;
}
int Stack::pop()
{
int topval;
topval=data[count];
count--;
return(topval);
}
int Stack::empty()
{
if (count==0)
return TRUE;
else
return FALSE;
}
int Stack::full()
{
if (count==Stack_Size)
return TRUE;
else
return FALSE;
}
Functions shouldnt be declared inside the constructor: watch this code as an example:
Code:
class someclass
{
someclass();
void somefunction();
int somenumber;
};
someclass::someclass()
{
somenumber = 0;
}
void someclass::somefunction()
{
//some code here
}
Code:
while(1)
{
cout<<"enter a digit";
cin>>number;
if (number>9)
break;
if (contents.full())
cout<<"no more space";
break;
else
contents.push(number);
cout<<"The values that were popped from the stack are";
while (!contents.empty())
{
cout<<contents.pop()<<endl;
}
return 0;
}
well you should check use of { and }
you have a little too few here: I *think* this is what you meant:
Code:
while(1)
{
cout<<"enter a digit";
cin>>number;
if (number>9)
break;
if (contents.full())
{
cout<<"no more space";
break;
}
else
contents.push(number);
}
cout<<"The values that were popped from the stack are";
while (!contents.empty())
{
cout<<contents.pop()<<endl;
}
return 0;
}
Or something like that, but you had a little too few brackets. Also please post the errors you get (if you get any but you should). Also like it is in your code now you have declared main as a part of the constructor to the Stack class.