Question: I need help with a programming assignment . Look at the question and please respond to both parts part 1 Build a class listType based

I need help with a programming assignment . Look at the question and please respond to both parts

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() (, chapter 4, p236) to handle invalid index parameter of at(): add this line as the first statement into at(): assert(index >= 0 && index

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:

I need help with a programming assignment . Look at the question

list one : [10, 20 Is 40 in list one? Answer -1 means no -1 Is 10 in list one? Answer -1 means no> 0 list two: [100, 1000. 20. 101 list two after removing [aj: [1000, 20, 10 list one after + list two: 10. 20. 1000. 20. 101

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!