Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<iostream.h> int stack [15]; int i = -1 ; void star line ( ) { for(int i

ID: 3610167 • Letter: #

Question

#include<iostream.h>
int stack [15];
int i = -1 ;
void star line ( )

{
for(int i=o; i<45;i++)
cout<<"*";
cout<<endl;
}
void push(int k)
i++;
if(i<15)
stack[i]=k
if(i>14)
{
cout<<"the stack is full"<<endl;
i--;
}
}
int pop( )
int buffer;
if(i>-1)
{
buffre=stack[i];
i--;
}
if(i<0)
cout<<"the stack is empty"<< endl;
return(buffer)
}
void main ( )
char input[4];
int z
star line( )
cout<<"this is a stack program"<<endl;
star line ( )
while (true)
{
cin>>input;
if(input[0]'p'&&input[1]=='u'&&input[2]=='s'&&input[3]=='h')
cout<<enter the value of the element yuo want to push in thestack";cin>>z;
push(z);
}
else if (in put [0]=='p'&& in put[1]=='o'&&input[2]=='p')
z=pop( );
cout<<"the last element was pushed in the stack is"<<z<<endl;
}
else
cout<<"i can not understand your word "<< endl;
star line ( );
}
}

Explanation / Answer

#include<iostream.h>
int stack [15];
int i = -1 ;
void star line ( )

{
for(int i=o; i<45;i++)
cout<<"*";
cout<<endl;
}
void push(int k)
i++;
if(i<15)
stack[i]=k
if(i>14)
{
cout<<"the stack is full"<<endl;
i--;
}
}
int pop( )
int buffer;
if(i<0)
cout<<"the stack is empty"<< endl;
return(buffer)
}
else{
buffre=stack[i];
i--;
return buffer;
}

void main ( )
char input[4];
int z
star line( )
cout<<"this is a stack program"<<endl;
star line ( )
while (true)
{
cin>>input;
if(input[0]'p'&&input[1]=='u'&&input[2]=='s'&&input[3]=='h')
cout<<enter the value of the element yuo want to push in thestack";cin>>z;
push(z);
}
else if (in put [0]=='p'&& in put[1]=='o'&&input[2]=='p')
z=pop( );
cout<<"the last element was pushed in the stack is"<<z<<endl;
}
else
cout<<"i can not understand your word "<< endl;
star line ( );
}
}

I hope this will helps to you