using namespace std;
class Pancake {
private:
int top;
int arr[10];
public:
Pancake() {
top = -1;
for (int i = 0; i < 5;="" i++)="">
arr[i] = 0;
}
}
bool isEmpty() {
if (top == -1)
return true;
else
return false;
}
bool isFull() {
if (top == 4)
return true;
else
return false;
}
void push(int val) {
if (isFull()) {
cout < "pancakes="" overflow"=""><>
} else {
top++; // 1
arr[top] = val;
}
}
int pop() {
if (isEmpty()) {
cout < "pancakes="" underflow"=""><>
return 0;
} else {
int popValue = arr[top];
arr[top] = 0;
top--;
return popValue;
}
}
int count() {
return (top + 1);
}
int peek(int pos) {
if (isEmpty()) {
cout < "pancake="" underflow"=""><>
return 0;
} else {
return arr[pos];
}
}
void display() {
cout < "all="" values="" in="" the="" pancake="" are="" "=""><>
for (int i = 4; i >= 0; i--) {
cout < arr[i]=""><>
}
}
};
int main() {
Pancake s1;
int option, postion, value;
do {
cout < "what="" operation="" do="" you="" want="" to="" perform?="" select="" option="" number.="" enter="" 0="" to="" exit."=""><>
cout < "1.="" push()"=""><>
cout < "2.="" pop()"=""><>
cout < "3.="" isempty()"=""><>
cout < "4.="" isfull()"=""><>
cout < "5.="" peek()"=""><>
cout < "6.="" count()"=""><>
cout < "7.="" display()"=""><>
cout < "8.="" clear="" screen"="">< endl=""><>
cin >> option;
switch (option) {
case 0:
break;
case 1:
cout < "enter="" an="" item="" to="" push="" in="" the="" pancake"=""><>
cin >> value;
s1.push(value);
break;
case 2:
cout < "pop="" function="" called="" -="" poped="" value:="" "="">< s1.pop()=""><>
break;
case 3:
if (s1.isEmpty())
cout < "pancake="" is="" empty"=""><>
else
cout < "pancake="" is="" not="" empty"=""><>
break;
case 4:
if (s1.isFull())
cout < "pancake="" is="" full"=""><>
else
cout < "pancake="" is="" not="" full"=""><>
break;
case 5:
cout < "enter="" position="" of="" item="" you="" want="" to="" peek:="" "=""><>
cin >> postion;
cout < "peek="" function="" called="" -="" value="" at="" position="" "="">< postion="">< "="" is="" "="">< s1.peek(postion)=""><>
break;
case 6:
cout < "count="" function="" called="" -="" number="" of="" items="" in="" the="" pancake="" are:="" "="">< s1.count()=""><>
break;
case 7:
cout < "display="" function="" called="" -="" "=""><>
s1.display();
break;
case 8:
system("cls");
break;
default:
cout < "enter="" proper="" option="" number="" "=""><>
}
} while (option != 0);
return 0;
}