Now, you'll be modifying listType to have a dynamic array where its size can grow beyond the 1000 integer limit, but only allocate more space if it is needed as your list grows. In the listTypeImp.cpp...

1 answer below »

Now, you'll be modifying listType to have a dynamic array where its size can grow beyond the 1000 integer limit, but only allocate more space if it is needed as your list grows.


In the listTypeImp.cpp file, you'll need to make modifications to theaddmethod, theconstructor, thedeconstructor, thecopy constructor, andoverloading the assignment operator.


You will only need to submit the listTypeImp.cpp file.


Remember that with any class that uses pointers, you should always:


1) Implement a Deconstructor


2) Implement the Copy Constructor so that You Have Deep Copies as Opposed to Shallow Copies


3) Overload the Assignment Operator




#ifndef LISTTYPE_H #define LISTTYPE_H class listType { public: // Returns True if List Size is 0 bool isEmpty() const; // Returns True if List Size is Same As Max Size bool isFull() const; // Returns Index for First Occurance of Item in List, -1 if Not Found int search(int searchItem) const; // Adds New Element to End of List void add(int newElement); // Removes First Occurance of Element in List void remove(int removeElement); // Resets List to be Empty List void clear(); // Prints (cout) All Contents of List void print() const; // Returns Value of Element at Index Provided int getElementAtPosition(int index) const; // Returns Current List Size int size() const; // Returns True if OtherList and This List Have the Same Elements // In The Same Order bool isEqual(const listType &otherList) const; // Returns the Maximum Number of Elements That Can be Stored int maxSize() const; // Constructor; Should Start New List as Empty List listType(); // Copy Constructor listType(const listType &otherList); // Deconstructor ~listType(); // Overload Assignment Operator const listType& operator= (const listType &otherList); private: int currentMaxSize; int *list; int listSize; }; #endif #include #include "listType.h" using namespace std; int main() { listType firstList; listType secondList; firstList.add(3); firstList.add(10); secondList.add(3); secondList.add(4); secondList.add(10); if (firstList.isEqual(secondList)) cout < "they="" are="" the="" same!"="">< endl;="" else="" cout="">< "the="" lists="" are="" different"="">< endl;="" cout="">< "the="" contents="" of="" the="" first="" list="" are:="" ";="" firstlist.print();="" cout="">< "the="" contents="" of="" the="" second="" list="" are:="" ";="" secondlist.print();="" cout="">< "assigned="" the="" second="" list="" to="" the="" first="" list."="">< endl;="" firstlist="secondList;" if="" (firstlist.isequal(secondlist))="" cout="">< "they="" are="" the="" same!"="">< endl;="" else="" cout="">< "the="" lists="" are="" different"="">< endl;="" cout="">< "the="" contents="" of="" the="" first="" list="" are:="" ";="" firstlist.print();="" cout="">< "the="" contents="" of="" the="" second="" list="" are:="" ";="" secondlist.print();="" cout="">< "added="" 12="" and="" removed="" 3="" from="" the="" second="" list."="">< endl;="" secondlist.add(12);="" secondlist.remove(3);="" if="" (firstlist.isequal(secondlist))="" cout="">< "they="" are="" the="" same!"="">< endl;="" else="" cout="">< "the="" lists="" are="" different"="">< endl;="" cout="">< "the="" contents="" of="" the="" first="" list="" are:="" ";="" firstlist.print();="" cout="">< "the="" contents="" of="" the="" second="" list="" are:="" ";="" secondlist.print();="" cout="">< "added="" 4="" to="" the="" first="" list."="">< endl;="" firstlist.add(4);="" cout="">< "the="" size="" of="" the="" first="" list="" is:="" "="">< firstlist.size()="">< endl;="" cout="">< "cleared="" out="" the="" second="" list."="">< endl;="" secondlist.clear();="" cout="">< "the="" size="" of="" the="" second="" list="" is:="" "="">< secondlist.size()="">< endl;="" cout="">< "the="" contents="" of="" the="" first="" list="" are:="" ";="" firstlist.print();="" cout="">< "the="" position="" of="" 10="" in="" the="" first="" list="" is:="" "="">< firstlist.search(10)="">< endl;="" cout="">< "the="" element="" at="" position="" 0="" of="" the="" first="" list="" is:="" "="">< firstlist.getelementatposition(0)="">< endl;="" cout="">< "i="" am="" printing="" out="" the="" contents="" of="" the="" first="" list="" from="" a="" 'for="" loop':="" "="">< endl;="" for="" (int="" i="0;">< firstlist.getelementatposition(i)="">< '="" ';="" cout="">< endl;="" cout="">< "the="" current="" max="" size="" is="" :="" "="">< firstlist.maxsize()="">< endl;="" for="" (int="" i="0;"><10000; i++)="" {="" firstlist.add(i);="" }="" cout="">< "the="" current="" max="" size="" is="" :="" "="">< firstlist.maxsize()="">< endl;="" return="" 0;="" }="" #include=""> #include "listType.h" using namespace std; bool listType::isEmpty() const { return listSize == 0; } bool listType::isFull() const { return listSize == currentMaxSize; } int listType::search(int searchItem) const { int index = -1; for (int i=0; i< list[i]="">< '="" ';="" }="" cout="">< endl;="" }="" int="" listtype::getelementatposition(int="" index)="" const="" {="" if="" (index="">= 0 && index < listsize)="" return="" list[index];="" else="" return="" 0;="" }="" int="" listtype::size()="" const="" {="" return="" listsize;="" }="" bool="" listtype::isequal(const="" listtype="" &otherlist)="" const="" {="" bool="" samesize="listSize" =="otherList.size();" bool="" equallists="sameSize;" if="" (samesize)="" {="" for="" (int="" i="0;">
Answered Same DayApr 05, 2021

Answer To: Now, you'll be modifying listType to have a dynamic array where its size can grow beyond the 1000...

Pritam answered on Apr 06 2021
126 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here