http://www.c-jump.com/bcc/c255c/c255syllabus.htmThe purpose of this assignment is to create a C++ class that implements a stack of integers.
Create a class IntStack to keep a stack of integers. The initial implementation of the stack should be as an array of fixed size of 100 integers.
Write member function void reset() which will reset the stack, i.e. make it empty. Write member functions, push() and pop():
class IntStack
{
//...
void reset();
void push( int n );
int pop();
//...
};
Make sure these routines maintain the integrity of the object under error conditions and signal such conditions by printing error messages to cerr.
Overload push() to take in an array of integers and push them onto the stack:
class IntStack
{
//...
void push( int a[], size_t array_size );
//...
};
Push a[0] first and then a[1] and so forth until array_size.
Overload pop() to return n integers in an array:
class IntStack
{
//...
void pop( int a[], size_t n );
//...
};
So if (n == 2),
then
(a[0] == top of stack),
and
(a[1] == next element on the stack).
The effect of the following code should be to reverse the integers in arr:
int arr[ 5 ] = { 1, 2, 3, 4, 5};
IntStack st;
st.push( arr, 5 );
st.pop( arr, 5 );
Write member functions
class IntStack
{
//...
bool is_full();
bool is_empty();
//...
};
to return if the stack is full or not, and if the stack is empty or not.
Write a global function
void print_stack( IntStack* pstack );
which will print the integers on the stack to cout. Print each integer on a seperate line. Make it a friend of IntStack class, so it can access the stack without popping any elements.
Submit your source file(s) via e-mail attachment sent to:
Igor.Kholodov@bristolcc.edu
Please ZIP multiple files into a single archive before you submit your work.
Thank you, and good luck!