http://www.c-jump.com/bcc/c255c/c255syllabus.htm
The 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.
Save local copy of all source files in your program.
Go to CIS-255 online website. You should have already received your login and password for this website. If not, then email me at
and I will reply back with your access credentials.
On the Main Menu, follow the link to Submit Homework, select Project 1/Part 1, and upload your source files.
Note: the system will display an 8-digit confirmation number once the file is successfully uploaded. You can save the confirmation number for your own records, but this is not a required step and no further action is needed on your part.
Let me know if you are experiencing any problems, otherwise -- good luck on your first assignment!