Hello, can anyone help, i will post the code below, but i have been given an assignment to create a stack and implement it showing test plans and debugging, but im very stuck and every tutorial i come across uses classes which im not allowed to do, any help on getting it working would be much appreciated.
#include<iostream>
#include<stdlib.h>
usingnamespace std;
int stack[5];
int top;
void push (int x)
{
if (top>5)
{
cout<<"your stack has overflowed or is full, returning to a past state"<<endl;
return;
}
stack[++top]=x;
cout<<"inserted2"<<x<<endl;
}
void pop()
{
if(top<0)
{
cout<<"stack is underflowed,restoring last state"<<endl;
return;
}
cout<<"deleted"<<stack[top--];
}
void display()
{
if (top<0)
{
cout<<"The stack is empty"<<endl;
return;
}
for ( int i = top;i>=0;i--)
cout<<stack[i]<< " ";
}
int main;
{
int choice;
int ele;
stack stk;
while(1)
{
cout<< "Implementation of a stack"<<endl;
cout<<" The following programme represents a stack, which follows the L.I.f.O system\n"endl;
cout<< "L.I.F.O means Last in, First Out.\n For example, if you stack dinner plates\nthe last one to be stacked ontop of the stack, will be the first to be used"endl;
cout<<" From the stack you can: Push - adds to the stack, Pop - Removes from the stack"<<endl;
cout<<"You can also find out if the stack is full or empty, and have the stack be printed for a visual display"<<endl;
cout<<"1.push, 2.pop, 3.display, 4. exit"<<endl;
cout<<" Please enter your choice"<<endl;
cin>>choice;
switch(choice)
{
case 1: cout<<"eneter the number of elements you wish to have, remember the stack can only hold five elements"<<endl;
cin>>ele;
stk.push (ele);
break;
case 2: cout<<"you have popped an element out!"<<endl;
stk.pop();
break;
case 3: stk.display()
case 4: exit(0)
}
}
return (0);
}