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

really confuse me. pls use c++, thank u so much Enter the full contents of your

ID: 3592739 • Letter: R

Question




really confuse me. pls use c++, thank u so much

Enter the full contents of your HW4-Todo-StackArray.cpp file. Your HW4-Todo-StackArrayList.cpp file will be compiled with a main.cpp file and the HW4-Todo-StackArray cpp that was provided in the write-up. The operations performed with your class implementation will be visible in the output box after clicking the check button Allowable include statements for this assignment are: #include-io stream» #include "Hw4 . Todo-StackAr ray .hpp" Answer: (penalty regime: 0 %)

Explanation / Answer

#include<iostream.h>

#include<conio.h>

#include<process.h>

#define MAX 5

class Stack

{

int top;

int arr[MAX];

int IsEmpty()

{

if(top == -1)

return 1;

else

return 0;

}

int IsFull()

{

if(top == MAX-1)

return 1;

else

return 0;

}

public :

Stack()

{

top = -1;

}

void Push();

void Pop();

void Peek();

void Display();

};

void Stack :: Push()

{

if(IsFull())

{

cout<<" The stack is full. Cannot push new item.";

getch();

return;

}

else

{

cout<<" Enter the number : ";

cin>>arr[++top];

}

}

void Stack :: Pop()

{

if(IsEmpty())

{

cout<<" The stack is empty. Cannot pop.";

getch();

return;

}

else

top--;

}

void Stack :: Peek()

{

if(IsEmpty())

{

cout<<" The stack is empty. Cannot peek.";

getch();

return;

}

else

cout<<" The top item is : "<<arr[top];

}

void Stack :: Display()

{

int i;

if(IsEmpty())

{

cout<<" The stack is empty. Cannot display.";

getch();

return;

}

else

{

for(i = top ; i >= 0 ; i--)

cout<<" "<<arr[i];

}

}

void main(void)

{

Stack obj;

int ch;

while(1)

{

clrscr();

cout<<" MENU";

cout<<" ____";

cout<<" 1. Push.";

cout<<" 2. Pop.";

cout<<" 3. Peek.";

cout<<" 4. Display in LIFO.";

cout<<" 5. Exit.";

cout<<" Enter your choice : ";

cin>>ch;

switch(ch)

{

case(1) : obj.Push();

break;

case(2) : obj.Pop();

break;

case(3) : obj.Peek();

break;

case(4) : obj.Display();

break;

case(5) : cout<<" Exiting...";

getch();

exit(0);

default : cout<<" Invalid input.";

getch();

}

getch();

}

}