Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Add a new method called \"contains\" to the array-based implementation of the li

ID: 3574547 • Letter: A

Question

Add a new method called "contains" to the array-based implementation of the list calss tamplate ArrayList. The specification for the method is

/** Sees wether a given entry occurs in a given list.

@param anEntry The object that is the desired entry.

@return true if the list contains anEntry, or false if not. */

bool contains(const ItemType& anEntry) const;

Reminder: the data members of the ArrayList class template are:

stactic const int DEFAULT_CAPACOTY = 5; //Initial list capacity

ItemType items[DEFAULT_CAPACITY +1] //Array of list items

int itemCount;

int maxItems;

Reminde

Explanation / Answer

Here is the code for contains() method:

bool contains(const ItemType& anEntry)
{
for(int i = 0; i < itemCount; i++)
if(items[i] == anEntry)
return true;
return false;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote