10)Yao+Chong

code using namespace std;
 * 1) include

class stack { private: int top; char storage[5]; bool full; bool empty;

public: stack                 // Constructor {             int i;              top = -1;        // Initialize array to be empty. for (i=0; i<5; i++) {                 storage[i] = ' '; }             empty = true;    // the array is empty at first. full = false; };      ~stack {};

bool push(char a)      { if (is_full == true) {               return false; }           else {               storage[top+1] = a;   // when top is -1 (i.e. stack is empty, push pushes into storage[-1+1 = 0]                top++;                // top is now 0                if (top == 4)                {                       full = true;                             // Once top is 4, (i.e. array has 5 elements and is full)                       cout << "The stack is now full.\n";      // Informs the user that the stack is full.                }                else if (empty == true)                {                       empty = false;  // Once a character is pushed into the stack, it is not empty anymore.                }                return true;            }       };

char pop {           char temp; temp = storage[top]; top--; if (top == -1) {               empty = true;                            // Once top is -1, the stack is empty. cout << "The stack is now empty.\n";    // Informs the user that the stack is full. }           else if (full == true) {               full = false;     // After popping one element, the stack is no longer full. }           return temp; };

bool is_full {           return full;          // return the boolean value full };      bool is_empty {           return empty;         // return the boolean value empty }; };

/*Test your STACK class in the main program to demo that it works for 1)   Removing an item from a STACK  with no items 2)    Adding items to a STACK that has 4 items 3)   Adding an item to a STACK that has 5 items 4)    Show that the items in the STACK are in LIFO order.*/

int main {   stack stack1; char choice, inp, outp, addmore; int rep;

do {   cout << "Type U for push, small o to pop one, capital O to pop all, anything else to exit.\n"; cin >> choice; if (choice == 'u' || choice == 'U') {        if (stack1.is_full == true)            // push elements one at a time. {              cout << "The stack is full.\n";    // if the stack is full, the user cannot input new elements. }        else {              cout << "What do you want to put in the stack?\n"; cin >> inp; stack1.push(inp); }   }    else if (choice == 'o') {        if (stack1.is_empty == true)         // pop elements one at a time. {              cout << "The stack is empty.\n"; // if the stack is empty, the user cannot pop new elements. }        else {              outp = stack1.pop; cout << outp << endl; }   }    else if (choice == 'O') {        while (stack1.is_empty != true)      // pop elements until the stack is empty. {        outp = stack1.pop; cout << outp << endl; }   } } while (choice == 'u' || choice == 'U' || choice == 'o' || choice == 'O');

system("PAUSE"); return 0; } code