http://www.c-jump.com/bcc/c255c/c255syllabus.htm
The purpose of this assignment is to experiment with dynamic memory allocation.
Modify the internal implementation of IntStack so that it dynamically allocates the array when it is constructed. The following sample program dynamic_memory.cpp (download) demonstrates C++ allocation, re-allocation, and de-allocation of memory.
Add a default constructor that allocates a dynamic array of 100 integers.
Add a destructor that deallocates dynamic memory.
Write a second constructor that takes a single integer specifying the stack size. Your code should behave reasonably if there is insufficient memory to allocate a stack of the requested size. If the requested initial size is 0, it should still be possible to push the values onto the stack. Note that instead of writing a second constructor, you can instead provide just one constructor with a default argument; it's up to you.
Write a member function
void double_capacity();
which will double the size of the internal array and keep all the elements on the stack intact.
Write member function
size_t size();
which should return the current number of items on the stack.
Write member function
size_t capacity();
which should return the current size of the internal array.
Modify push() so that it automatically doubles the size of the stack if necessary to hold the item being pushed.
Write your main function that invokes and uses the functionality of the IntStack. Your stack should compile and run without problems against a sample main program like this: DynStackMain.cpp (download.)
Remember that all code should check for boundary/error conditions. For example, trying to pop off an empty stack should print out a useful error message. This and other error messages must be sent to std::cerr, not std::cout. Your project should consist of three files:
Save local copy of all source files in your program.
When ready, log into CIS-255 online website, follow the link to Submit Homework, and select Project 1/Part 2 to upload your source files. Alternatively, you may zip the folder with all of your source files and upload a single ZIP archive.
PLEASE DO NOT send project, EXE, or other MSVC artifacts on your system. I only need your C++ source files to grade the assignment.