#include #include #include #include #include #include #include #include #include #include class stack { public: int data; int *delptr; int dataout; int sarray[30]; void getready(); void push(int & data); void pop(int & dataout); void stacktop(int & data); void destroy(); private: int count ; }; void stack::getready(){ //purpose: this function sets variables to there proper position at the start // of the program //precondition: the variable count must exist as part of the class stack //postcondition: the variable count will be set to 1 count = 1; } void stack::push(int & data){ //purpose: this function adds an item to the top of a stack //precondition: a stack must exist; //postconditions: the stack will be one item bigger sarray[count] = data; count++; } void stack::pop(int & dataout){ //purpose: this function removes an item from the top of the stack //preconditions: stack has data //postconditions: stack will be one data item shorter count--; dataout = sarray[count]; } void stack::stacktop(int & data){ //purpose: this function will return the top of the stack without changing // anything //preconditions: a stack must exist in an instance of a class //postconditions: the top of the stack will be stored in the variable data count--; data = sarray[count]; count++; } void stack::destroy(){ //purpose: to free the memory up used by the instance of the class // note: this function really doesn't free up any memory // it just resets the array to 0 // further research is required to learn how to delete // instances of a class //precondition:a array has to exist in a class instance //post condition: array reset to zero while(count != 0){ count--; sarray[count] = 0; } sarray[count] = 0; }