Question: Provide an array implementation of a stack of double values. Make sure to look at the SimpleList Example code (at the bottom). That program illustrates
Provide an array implementation of a stack of double values. Make sure to look at the SimpleList Example code (at the bottom). That program illustrates the basics of working with a dynamically allocated array within a class. It also shows the start of how to work with a resize() or makeLarger() member function.
Provide all standard public stack methods, including push, pop, and a method that tests for the empty stack. Also provide a constructor, copy constructor, assignment operator, and a destructor. In addition, the stack class should have the following capabilities:
- A member function that gets the top item of the stack, without removing the item.
double peek();
- A member function that determines the size of the stack (i.e. the number of items in this stack).
int getSize();
- A overloaded assignment operator that calls destroy() and copy().
- Copy constructor that calls copy().
- A private member function that makes the array larger if the capacity of the array is being reached.
- A private member function that performs a deep copy of the stack. This function should be called by the operator= and the copy constructor.
void copy(const Stack & copy);
- A private member function that deletes the memory associated with a stack. This function should be called by operator= and the destructor.
destroy();
Writing your driver or main() function
Provide well thought out test driver code or main() test program to test the capabilities of your Stack class. It is your job to demonstrate functionality of your class and member functions in the driver. SHOW through various calls to ALL the functions you wrote that your Stack class works beautifully. Do not prompt the user for values. Your driver should have all the numbers and information embedded inside the driver to thoroughly show that your Stack class works. (For example, your class files could then be passed to another programmer who will then use your class in a larger application because now we all know it works through your driver testing it!)
Grading
The assignment will be graded in accordance with the Labs and Programming Assignment Expectation handout and the rubric posted on Canvas. Failure to adhere to the guideline could result in losing points.
Submitting your Program
You must submit three files:
- The header file: Stack.h
- The implementation file: Stack.cpp
- The driver program: wk8.cpp
_____________________________________________________________________________________________________________________________________________________
SimpleList Example Code
/******
ideone.com/41LFjF SimpleList CORRECT
*****/
#include
class SimpleList { public: SimpleList(); SimpleList(const SimpleList& ); ~SimpleList(); const SimpleList& operator=(const SimpleList & right);
void printList()const; void clear(); void add(int newItem); bool member(int anItem)const; int currentSize() const; private: //void makeLarger(); int * listptr; int size; int maxSize; };
int main() { SimpleList myList; myList.add(3); SimpleList secondList = myList; myList.add(4); secondList = myList; myList.add(5); myList.printList(); secondList.printList(); return 0; } SimpleList::SimpleList() { cout << "In null constructor" << endl; listptr = nullptr; size = 0; maxSize = 10; listptr = new int[maxSize]; } SimpleList::SimpleList(const SimpleList& orig) { cout << "In copy constructor" << endl; maxSize = orig.maxSize; listptr = new int[maxSize]; size = orig.size; for(int i = 0; i In null constructor In add In copy constructor In add In assignment operator In add 3 4 5 3 4 Destructor here Destructor here
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
