Please help me in this C program make sure it can run Create

Please help me in this C++ program

make sure it can run


Create a class/struct.

Members:
MaxSize const = 10
Define an array that holds 10 items.
Count - indicates how many items are on the stack.

Methods:
Push
- Accepts a number and adds to the top of the stack.
- If the stack is full emit an error indicating full.
Pop
- Returns a number from the top of the stack.
- If the stack is empty, emit an error indicating the stack is empty.
IsEmpty
- Returns a boolean indicating if the stack is empty.

Solution

#include #include #include using namespace std; struct stack { private: enum { MAX_SIZE = 10 }; int array[MAX_SIZE] ; // int count; //= 0; public: int stk[10]; int top; int count;// = 0; //public: bool full() const { return count == MAX_SIZE ; } /* bool empty() const { return count == 0 ; }*/ stack() { top = -1; } bool push(int element) { cout << \"\ Enter the element: \"; cin >> element; if( full() ) { cerr << \"stack is full\ \" ; //Is full not printing return false ; } stk[++top] = element; cout << \"Successfully inserted: \" << element << \"\ \"; count++; //cout << \"There are \" << count << \" items on the stack\ \"; //??? } bool empty() { if(count == 0 ) { cout << \"\ The stack is empty\ \ \"; //Is empty not printing return count == 0; } else { return false; } for(int i = top; i >= 0; i--) { cout << stk[i]<< \" \"; } } int pop() { if( empty()) { cerr << \"\ The stack is empty\ \"; //Is empty not printing return -1; } else { cout << \"\ The number on the top of the stack is: \" << stk[top--] << \"\ \"; //deleted element? } //--count ; // decrement count //return array[count] ; } }; int main() { int count = 0; stack stk ; int ch; // push values into the stack int v = 1 ; while( !stk.full() ) { stk.push(v) ; v *= 2 ; } // pop and print them out one by one while( !stk.empty() ) { cout << stk.pop() << \' \' ; cout << \'\ \' ; } system(\"pause\"); return 0; }
Please help me in this C++ program make sure it can run Create a class/struct. Members: MaxSize const = 10 Define an array that holds 10 items. Count - indicate

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site