Question: arrayListType.h ----------------------------- template class elemType> bool arrayListType ::isEmpty() const { return (length == 0); } template class elemType> bool arrayListType ::isFull() const { return (length

 arrayListType.h ----------------------------- template class elemType> bool arrayListType::isEmpty() const { return (length

== 0); } template class elemType> bool arrayListType::isFull() const { return (length

arrayListType.h

-----------------------------

== maxSize); } template class elemType> int arrayListType::listSize() const { return length;} template class elemType> int arrayListType::maxListSize() const { return maxSize; } template

template class elemType>

bool arrayListType::isEmpty() const

{

return (length == 0);

}

template class elemType>

bool arrayListType::isFull() const

{

return (length == maxSize);

}

template class elemType>

int arrayListType::listSize() const

{

return length;

}

template class elemType>

int arrayListType::maxListSize() const

{

return maxSize;

}

template class elemType>

void arrayListType::print() const

{

for (int i = 0; i

cout

cout

}

template class elemType>

bool arrayListType::isItemAtEqual

(int location, const elemType& item) const

{

return (list[location] == item);

}

template class elemType>

void arrayListType::insertAt

(int location, const elemType& insertItem)

{

if (location = maxSize)

cerr

else

if (length >= maxSize) //list is full

cerr

else

{

for (int i = length; i > location; i--)

list[i] = list[i - 1]; //move the elements down

list[location] = insertItem; //insert the item at the

length++; //increment the length

}

} //end insertAt

template class elemType>

void arrayListType::insertEnd(const elemType& insertItem)

{

if (length >= maxSize) //the list is full

cerr

else

{

list[length] = insertItem; //insert the item at the end

length++; //increment the length

}

} //end insertEnd

template class elemType>

void arrayListType::removeAt(int location)

{

if (location = length)

cerr

else

{

for (int i = location; i

list[i] = list[i+1];

length--;

}

} //end removeAt

template class elemType>

void arrayListType::retrieveAt

(int location, elemType& retItem) const

{

if (location = length)

cerr

else

retItem = list[location];

} //end retrieveAt

template class elemType>

void arrayListType::replaceAt

(int location, const elemType& repItem)

{

if (location = length)

cerr

else

list[location] = repItem;

} //end replaceAt

template class elemType>

void arrayListType::clearList()

{

length = 0;

} //end clearList

template class elemType>

int arrayListType::seqSearch(const elemType& item) const

{

int loc;

bool found = false;

for (loc = 0; loc

if (list[loc] == item)

{

found = true;

break;

}

if (found)

return loc;

else

return -1;

} //end seqSearch

template class elemType>

void arrayListType::insert(const elemType& insertItem)

{

int loc;

if (length == 0) //list is empty

list[length++] = insertItem; //insert the item and

//increment the length

else if (length == maxSize)

cerr

else

{

loc = seqSearch(insertItem);

if (loc == -1) //the item to be inserted

//does not exist in the list

list[length++] = insertItem;

else

cerr

}

} //end insert

templateclass elemType>

void arrayListType::remove(const elemType& removeItem)

{

int loc;

if (length == 0)

cerr

else

{

loc = seqSearch(removeItem);

if (loc != -1)

removeAt(loc);

else

cout

}

} //end remove

template class elemType>

arrayListType::arrayListType(int size)

{

if (size

{

cerr

maxSize = 100;

}

else

maxSize = size;

length = 0;

list = new elemType[maxSize];

assert(list != NULL);

}

template class elemType>

arrayListType::~arrayListType()

{

delete [] list;

}

template class elemType>

arrayListType::arrayListType

(const arrayListType& otherList)

{

maxSize = otherList.maxSize;

length = otherList.length;

list = new elemType[maxSize]; //create the array

assert(list != NULL); //terminate if unable to allocate

//memory space

for (int j = 0; j

list [j] = otherList.list[j];

} //end copy constructor

template class elemType>

const arrayListType& arrayListType::operator=

(const arrayListType& otherList)

{

if (this != &otherList) //avoid self-assignment

{

delete [] list;

maxSize = otherList.maxSize;

length = otherList.length;

list = new elemType[maxSize]; //create the array

assert(list != NULL); //if unable to allocate memory

//space, terminate the program

for (int i = 0; i

list[i] = otherList.list[i];

}

return *this;

}

#endif

arrayListType.h contains the definition of the template class arrayListType. Download the file and modify the class arrayListType in the following way: The function removeAt of the class arrayListType removes an element from the list by shifting the elements of the list. However, if the element to be removed is at the beginning of the list and the list is fairly large, it could take a lot of computer time. Because the list elements are in no particular order, you can simply remove the element by swapping the last element of the list with the item to be removed and reducing the length of the list. Rewrite the definition of the function removeAt using this technique. Upload your new version of the class. simple class rubric Criteria Ratings Pts class rubric 10 pts Full Marks O pts No Marks 1) the program solves the problem 2) the program uses constructors, destructors appropriately 3) the program uses mutators appropriately 4) the program uses accessors appropriately 5) the program uses custom methods appropriately 10 pts Total Points: 10 1. Data is almost always private. 2. No error message in constructors. The proper way to handle errors in constructors is to throw exceptions. Since we cannot throw exceptions, we replace bad values with good ones. 3. Avoid the "this" pointer. You can avoid it by using parameter names and local variable names that are not the same as class member names. 4. Constructors and mutators should not be interactive. 1 #ifndef H_arrayListType #define H_arrayListType 2 3 4 ****************** ******************* //********************* // Author: D.S. Malik 5 6 7 // This class specifies the members to implement the basic 8 // properties of array-based lists. 9 //************************************************************ 10 11 #include 12 #include 13 14 using namespace std; 15 16 template 17 class arrayListType 18 { 19 public: 20 const arrayListType& operators 21 (const arrayListType&); 22 I/Overloads the assignment operator|| 23 bool is Empty() const; 24 //Function to determine whether the list is empty 25 1/Postcondition: Returns true if the list is empty; 26 // otherwise, returns false. 27 bool is Full() const; 28 //Function to determine whether the list is full. 29 //Postcondition: Returns true if the list is full; 30 // otherwise, returns false. 31 int listSize() const; 32 //Function to determine the number of elements in the list 33 //Postcondition: Returns the value of length. 34 int maxListSize() const; 35 //Function to determine the size of the list. 36 //Postcondition: Returns the value of maxSize. 37 void print() const; 38 //Function to output the elements of the list 39 //Postcondition: Elements of the list are output on the 40 standard output device. 41 bool isItemAtEqual(int location, const elemType& item) const; 42 //Function to determine whether the item is the same 43 //as the item in the list at the position specified by 44 //Postcondition: Returns true if the list[location] 45 // is the same as the item; otherwise, 46 // returns false. 47 void insertAt(int location, const elemType& insert Item); 48 //Function to insert an item in the list at the 49 //position specified by location. The item to be inserted 50 //is passed as a parameter to the function. 51 //Postcondition: Starting at location, the elements of the 52 // list are shifted down, list[location] = insertItem;, 53 // and length++;. If the list is full or location is 54 // out of range, an appropriate message is displayed. 55 void insertEnd(const elemType& insertItem); 56 //Function to insert an item at the end of the list. 57 //The parameter insertItem specifies the item to be inserted. 58 1/Postcondition: list[length] = insertItem; and length++; 59 // If the list is full, an appropriate message is 60 // displayed. 61 void removeAt(int location); 62 // Function to remove the item from the list at the 63 //position specified by location 64 //Postcondition: The list element at list[location] is removed 65 // and length is decremented by 1. If location is out of 66 // range, an appropriate message is displayed. 67 void retrieveAt(int location, elemType& retItem) const; 68 //Function to retrieve the element from the list at the 69 //position specified by location. 70 //Postcondition: retItem = list[location] void removeAt(int location); //Function to remove the item from the list at the //position specified by location //Postcondition: The list element at list[location] is removed // and length is decremented by 1. If location is out of // range, an appropriate message is displayed. void retrieveAt(int location, elemType& retItem) const; //Function to retrieve the element from the list at the //position specified by location. //Postcondition: retItem = list[location] // If location is out of range, an appropriate message is // displayed. void replaceAt(int location, const elemType& repItem); //Function to replace the elements in the list at the //position specified by location. The item to be replaced //is specified by the parameter repItem. //Postcondition: list[location] = repItem // If location is out of range, an appropriate message is displayed. void clearList(); //Function to remove all the elements from the list. //After this operation, the size of the list is zero. //Postcondition: length = 0; int seqSearch(const elemType& item) const; //Function to search the list for a given item. //Postcondition: If the item is found, returns the location // in the array where the item is found; otherwise, // returns -1. void insert(const elem Type& insertItem); //Function to insert the item specified by the parameter //insert Item at the end of the list. However, first the //list is searched to see whether the item to be inserted //is already in the list. // Postcondition: list[length] = insertItem and length++ // If the item is already in the list or the list // is full, an appropriate message is displayed. void remove(const elemType& removeItem); //Function to remove an item from the list. The parameter //removeItem specifies the item to be removed. //Postcondition: If removeItem is found in the list, // it is removed from the list and length is // decremented by one. arrayListType(int size = 100); //constructor //Creates an array of the size specified by the //parameter size. The default array size is 100. //Postcondition: The list points to the array, length = 0, // and maxSize = size arrayListType(const arrayListType& otherList); //copy constructor warrayListType(); //destructor //Deallocates the memory occupied by the array. protected: elemType *list; //array to hold the list elements int length; //to store the length of the list int maxSize; //to store the maximum size of the list }

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!