Question: CS355 programming question Please make sure to do the first and second part Part 1 Build a class listType based on statically allocated array. Its
CS355 programming question
Please make sure to do the first and second part
Part 1
Build a class listType based on statically allocated array. Its declaration is provided below (and in shell code provided with this HW):
| const int MAX = 100; // max capacity for all listType objects
class listType { public: listType(int max = 5); // constructor // Post: maxSize MAX, MAX will be used // size
int getSize() const { return size; } // return # of elements actually stored int getMaxSize() const { return maxSize; } // return capacity bool isEmpty() const { return size == 0; } bool isFull() const { return size == maxSize; }
int search(int element) const; // look for an item. return index of first occurrence int at(int index) const; // return element at a specific location void print() const; // print content of list on screen in format of [a, b, c] (like what ArrayList in Java does)
bool insert(int element); // append/insert an element at the end bool insert(int index, int element); // insert an element into location index. // Shifts the element currently at that index (if any) and any subsequent elements to the right
bool remove(int index); // remove element at the specified location
private: int dataArr[MAX]; // static array storing data items int size; // actual # of elements stored. size int maxSize; // The capacity of this listType obj. 0 };
|
This class behaves like ArrayList in Java, except that each object has a capacity limit maxSize. The elements should always be stored at index [0] ~ [size-1] without any holes between.
Note that the definition of four of the member functions are already provided as inline functions.
search() will return the index of the first occurrence of element if found, otherwise return -1.
Use assert() ( The two insert()s and the remove() should return true when the operation is done successfully, and return false when the operation fails, such as attempt to insert into a full list, remove from an empty list, or if an invalid index is provided. Provide appropriate driver code to test this class thoroughly (dont need to test the four given functions) before proceeding to Part 2. Part 2 Modify your listType program from Part 1. Overload output operator ( remove member function print() Overload binary + operator as a member to add two listType objects: should return a listType object which contains all elements from the two operands (two listType objects). You dont need to handle duplicates or order the elements in any specific way. Modify your driver accordingly to test those two operators. Here is the output of my partial driver: Organize your program into header file (interface), implementation file, and driver file. Use #include guard with the header file.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
