Question

This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...

This project is divided into 3 parts:

Part 1. Create a new project and download the arrayList and unorderedArrayList templates that are attached. Create a header file for your unorderedSet template and add it to the project. An implementation file will not be needed since the the new class will be a template. Override the definitions of insertAt, insertEnd, and replaceAt in the unorderedSet template definition. Implement the template member functions so that all they do is verify that the item to be added is not already in the list (hint - use the seqeuntialSearch function from the base class). If the item can be added, invoke the base class versions of the functions to perform the actual operation. Note that you may need to use the this pointer to access members of the base class from the derived class. (10 points)

Part 2. Overload the + operator to perform the operation of set union. Overload the -operator to perform the operation of set intersection. Overload as member functions and document your new functions appropriately. (5 points)

Part 3. Write a client program to show that your template will correctly handle sets containing integers and sets containing strings. Your client program should

  • Create an array of integers and an array of strings.
  • Create an unorderedSet object that will contain integers and add the values from the integer array to the set (use insertEnd).
  • Create another unorderedSet object that will contain strings and add the values from the string array to the set (use insertEnd).
  • Verify that insertEnd will not allow a duplicate entry to be made in each of the sets (use the print function to display the results).
  • Verify that insertAt will allow a unique item, but not a duplicate entry to be made in each of the sets.
  • Verify that replaceAt will allow a unique item, but not a duplicate entry to be made in each of the sets.
  • To test your union and intersection operations. Create three sets for each data type. Add items to two of them. Perform the union operation by adding the two sets and assigning the result to the third set. Repeat for the intersection operation.

arrayListType.h

#ifndef H_arrayListType

#define H_arrayListType

#include <iostream>

using namespace std;

template <class elemType>

class arrayListType

{

public:

const arrayListType<elemType>&

operator=(const arrayListType<elemType>&);

//Overloads the assignment operator

bool isEmpty() const;

//Function to determine whether the list is empty

//Postcondition: Returns true if the list is empty;

// otherwise, returns false.

bool isFull() const;

//Function to determine whether the list is full

//Postcondition: Returns true if the list is full;

// otherwise, returns false.

int listSize() const;

//Function to determine the number of elements in

//the list.

//Postcondition: Returns the value of length.

int maxListSize() const;

//Function to determine the maximum size of the list

//Postcondition: Returns the value of maxSize.

void print() const;

//Function to output the elements of the list

//Postcondition: Elements of the list are output on the

// standard output device.

bool isItemAtEqual(int location, const elemType& item) const;

//Function to determine whether item is the same as

//the item in the list at the position specified

//by location.

//Postcondition: Returns true if the list[location]

// is the same as item; otherwise,

// returns false.

// If location is out of range, an

// appropriate message is displayed.

virtual void insertAt(int location, const elemType& insertItem) = 0;

//Function to insert insertItem in the list at the

//position specified by location.

//Note that this is an abstract function.

//Postcondition: Starting at location, the elements of

// the list are shifted down,

// list[location] = insertItem; length++;

// If the list is full or location is out of

// range, an appropriate message is displayed.

virtual void insertEnd(const elemType& insertItem) = 0;

//Function to insert insertItem an item at the end of

//the list. Note that this is an abstract function.

//Postcondition: list[length] = insertItem; and length++;

// If the list is full, an appropriate

// message is displayed.

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.

virtual void replaceAt(int location, const elemType& repItem) = 0;

//Function to replace repItem the elements in the list

//at the position specified by location.

//Note that this is an abstract function.

//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;

virtual int seqSearch(const elemType& searchItem) const = 0;

//Function to search the list for searchItem.

//Note that this is an abstract function.

//Postcondition: If the item is found, returns the

// location in the array where the item is

// found; otherwise, returns -1.

virtual void remove(const elemType& removeItem) = 0;

//Function to remove removeItem from the list.

//Note that this is an abstract function.

//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<elemType>& otherList);

//Copy constructor

virtual ~arrayListType();

//Destructor

//Deallocate the memory occupied by the array.

protected:

elemType *list; //array to hold the list elements

int length; //variable to store the length of the list

int maxSize; //variable to store the maximum

//size of the list

};


template <class elemType>

bool arrayListType<elemType>::isEmpty() const

{

return (this->length == 0);

}

template <class elemType>

bool arrayListType<elemType>::isFull() const

{

return (this->length == this->maxSize);

}

template <class elemType>

int arrayListType<elemType>::listSize() const

{

  return this->length;

}

template <class elemType>

int arrayListType<elemType>::maxListSize() const

{

  return this->maxSize;

}

template <class elemType>

void arrayListType<elemType>::print() const

{

for (int i = 0; i < this->length; i++)

cout << list[i] << " ";

cout << endl;

}

template <class elemType>

bool arrayListType<elemType>::isItemAtEqual(int location,

const elemType& item) const

{

if (location < 0 || location >= this->length)

{

cout << "The location of the item to be removed "

<< "is out of range." << endl;

return false;

}

else

return (list[location] == item);

}

template <class elemType>

void arrayListType<elemType>::removeAt(int location)

{

if (location < 0 || location >= this->length)

cout << "The location of the item to be removed "

<< "is out of range." << endl;

else

{

for (int i = location; i < this->length - 1; i++)

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

this->length--;

}

} //end removeAt

template <class elemType>

void arrayListType<elemType>::retrieveAt(int location,

elemType& retItem) const

{

if (location < 0 || location >= this->length)

cout << "The location of the item to be retrieved is "

<< "out of range" << endl;

else

retItem = list[location];

} //end retrieveAt

template <class elemType>

void arrayListType<elemType>::clearList()

{

this->length = 0;

} //end clearList

template <class elemType>

arrayListType<elemType>::arrayListType(int size)

{

if (size <= 0)

{

cout << "The array size must be positive. Creating "

<< "an array of the size 100. " << endl;

this->maxSize = 100;

}

else

this->maxSize = size;

this->length = 0;

list = new elemType[this->maxSize];

}

template <class elemType>

arrayListType<elemType>::~arrayListType()

{

delete [] list;

}

template <class elemType>

arrayListType<elemType>::arrayListType(const arrayListType<elemType>& otherList)

{

this->maxSize = otherList.maxSize;

this->length = otherList.length;

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

for (int j = 0; j < this->length; j++) //copy otherList

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

}//end copy constructor

template <class elemType>

const arrayListType<elemType>& arrayListType<elemType>::operator=

(const arrayListType<elemType>& otherList)

{

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

{

delete [] list;

this->maxSize = otherList.maxSize;

this->length = otherList.length;

list = new elemType[this->maxSize];

for (int i = 0; i < this->length; i++)

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

}

return *this;

}

#endif

unorderedArrayListType.h

#ifndef H_unorderedArrayListType

#define H_unorderedArrayListType

#include "arrayListType.h"

template <class elemType>

class unorderedArrayListType: public arrayListType<elemType>

{

public:

void insertAt(int location, const elemType& insertItem);

void insertEnd(const elemType& insertItem);

void replaceAt(int location, const elemType& repItem);

int seqSearch(const elemType& searchItem) const;

void remove(const elemType& removeItem);

unorderedArrayListType(int size = 100);

//Constructor

};

template <class elemType>

void unorderedArrayListType<elemType>::insertAt(int location,

const elemType& insertItem)

{

if (location < 0 || location >= this->maxSize)

cout << "The position of the item to be inserted "

<< "is out of range." << endl;

else if (this->length >= this->maxSize) //list is full

cout << "Cannot insert in a full list" << endl;

else

{

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

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

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

//the specified position

this->length++; //increment the length

}

} //end insertAt

template <class elemType>

void unorderedArrayListType<elemType>::insertEnd

(const elemType& insertItem)

{

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

cout << "Cannot insert in a full list." << endl;

else

{

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

this->length++; //increment the length

}

} //end insertEnd

template <class elemType>

int unorderedArrayListType<elemType>::seqSearch

(const elemType& searchItem) const

{

int loc;

bool found = false;

for (loc = 0; loc < this->length; loc++)

if (this->list[loc] == searchItem)

{

found = true;

break;

}

if (found)

return loc;

else

return -1;

} //end seqSearch

template <class elemType>

void unorderedArrayListType<elemType>::remove

(const elemType& removeItem)

{

int loc;

if (this->length == 0)

cout << "Cannot delete from an empty list." << endl;

else

{

loc = seqSearch(removeItem);

if (loc != -1)

this->removeAt(loc);

else

cout << "The item to be deleted is not in the list."

<< endl;

}

} //end remove

template <class elemType>

void unorderedArrayListType<elemType>::replaceAt(int location,

const elemType& repItem)

{

if (location < 0 || location >= this->length)

cout << "The location of the item to be "

<< "replaced is out of range." << endl;

else

this->list[location] = repItem;

} //end replaceAt

template <class elemType>

unorderedArrayListType<elemType>::unorderedArrayListType(int size)

: arrayListType<elemType>(size)

{

}

#endif

This is what I have.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// arrayListType.h

#ifndef H_arrayListType

#define H_arrayListType

#include <iostream>

using namespace std;

template <class elemType>

class arrayListType

{

public:

const arrayListType<elemType>&

operator=(const arrayListType<elemType>&);

//Overloads the assignment operator

bool isEmpty() const;

//Function to determine whether the list is empty

//Postcondition: Returns true if the list is empty;

// otherwise, returns false.

bool isFull() const;

//Function to determine whether the list is full

//Postcondition: Returns true if the list is full;

// otherwise, returns false.

int listSize() const;

//Function to determine the number of elements in

//the list.

//Postcondition: Returns the value of length.

int maxListSize() const;

//Function to determine the maximum size of the list

//Postcondition: Returns the value of maxSize.

void print() const;

//Function to output the elements of the list

//Postcondition: Elements of the list are output on the

// standard output device.

bool isItemAtEqual(int location, const elemType& item) const;

//Function to determine whether item is the same as

//the item in the list at the position specified

//by location.

//Postcondition: Returns true if the list[location]

// is the same as item; otherwise,

// returns false.

// If location is out of range, an

// appropriate message is displayed.

virtual void insertAt(int location, const elemType& insertItem) = 0;

//Function to insert insertItem in the list at the

//position specified by location.

//Note that this is an abstract function.

//Postcondition: Starting at location, the elements of

// the list are shifted down,

// list[location] = insertItem; length++;

// If the list is full or location is out of

// range, an appropriate message is displayed.

virtual void insertEnd(const elemType& insertItem) = 0;

//Function to insert insertItem an item at the end of

//the list. Note that this is an abstract function.

//Postcondition: list[length] = insertItem; and length++;

// If the list is full, an appropriate

// message is displayed.

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.

virtual void replaceAt(int location, const elemType& repItem) = 0;

//Function to replace repItem the elements in the list

//at the position specified by location.

//Note that this is an abstract function.

//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;

virtual int seqSearch(const elemType& searchItem) const = 0;

//Function to search the list for searchItem.

//Note that this is an abstract function.

//Postcondition: If the item is found, returns the

// location in the array where the item is

// found; otherwise, returns -1.

virtual void remove(const elemType& removeItem) = 0;

//Function to remove removeItem from the list.

//Note that this is an abstract function.

//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<elemType>& otherList);

//Copy constructor

virtual ~arrayListType();

//Destructor

//Deallocate the memory occupied by the array.

protected:

elemType *list; //array to hold the list elements

int length; //variable to store the length of the list

int maxSize; //variable to store the maximum

//size of the list

template <class U>

friend std::ostream& operator<<(std::ostream&, const arrayListType<U>&); // friend function to display the elements of list using << operator

};

template <class elemType>

bool arrayListType<elemType>::isEmpty() const

{

return (this->length == 0);

}

template <class elemType>

bool arrayListType<elemType>::isFull() const

{

return (this->length == this->maxSize);

}

template <class elemType>

int arrayListType<elemType>::listSize() const

{

return this->length;

}

template <class elemType>

int arrayListType<elemType>::maxListSize() const

{

return this->maxSize;

}

template <class elemType>

void arrayListType<elemType>::print() const

{

for (int i = 0; i < this->length; i++)

cout << list[i] << " ";

cout << endl;

}

template <class elemType>

bool arrayListType<elemType>::isItemAtEqual(int location,

const elemType& item) const

{

if (location < 0 || location >= this->length)

{

cout << "The location of the item to be removed "

<< "is out of range." << endl;

return false;

}

else

return (list[location] == item);

}

template <class elemType>

void arrayListType<elemType>::removeAt(int location)

{

if (location < 0 || location >= this->length)

cout << "The location of the item to be removed "

<< "is out of range." << endl;

else

{

for (int i = location; i < this->length - 1; i++)

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

this->length--;

}

} //end removeAt

template <class elemType>

void arrayListType<elemType>::retrieveAt(int location,

elemType& retItem) const

{

if (location < 0 || location >= this->length)

cout << "The location of the item to be retrieved is "

<< "out of range" << endl;

else

retItem = list[location];

} //end retrieveAt

template <class elemType>

void arrayListType<elemType>::clearList()

{

this->length = 0;

} //end clearList

template <class elemType>

arrayListType<elemType>::arrayListType(int size)

{

if (size <= 0)

{

cout << "The array size must be positive. Creating "

<< "an array of the size 100. " << endl;

this->maxSize = 100;

}

else

this->maxSize = size;

this->length = 0;

list = new elemType[this->maxSize];

}

template <class elemType>

arrayListType<elemType>::~arrayListType()

{

delete [] list;

}

template <class elemType>

arrayListType<elemType>::arrayListType(const arrayListType<elemType>& otherList)

{

this->maxSize = otherList.maxSize;

this->length = otherList.length;

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

for (int j = 0; j < this->length; j++) //copy otherList

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

}//end copy constructor

template <class elemType>

const arrayListType<elemType>& arrayListType<elemType>::operator=

(const arrayListType<elemType>& otherList)

{

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

{

delete [] list;

this->maxSize = otherList.maxSize;

this->length = otherList.length;

list = new elemType[this->maxSize];

for (int i = 0; i < this->length; i++)

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

}

return *this;

}

//--------------------

// non-member, friend

//--------------------

template <class itemType>

std::ostream& operator<<(std::ostream& out, const arrayListType<itemType>& obj)

{

for (int i = 0; i < obj.length; i++)

out << obj.list[i] << " ";

return out;

} //end operator<<

#endif

// unorderedArrayListType.h

#ifndef H_unorderedArrayListType

#define H_unorderedArrayListType

#include "arrayListType.h"

template <class elemType>

class unorderedArrayListType: public arrayListType<elemType>

{

public:

void insertAt(int location, const elemType& insertItem);

void insertEnd(const elemType& insertItem);

void replaceAt(int location, const elemType& repItem);

int seqSearch(const elemType& searchItem) const;

void remove(const elemType& removeItem);

unorderedArrayListType(int size = 100);

//Constructor

};

template <class elemType>

void unorderedArrayListType<elemType>::insertAt(int location,

const elemType& insertItem)

{

if (location < 0 || location >= this->maxSize)

cout << "The position of the item to be inserted "

<< "is out of range." << endl;

else if (this->length >= this->maxSize) //list is full

cout << "Cannot insert in a full list" << endl;

else

{

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

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

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

//the specified position

this->length++; //increment the length

}

} //end insertAt

template <class elemType>

void unorderedArrayListType<elemType>::insertEnd

(const elemType& insertItem)

{

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

cout << "Cannot insert in a full list." << endl;

else

{

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

this->length++; //increment the length

}

} //end insertEnd

template <class elemType>

int unorderedArrayListType<elemType>::seqSearch

(const elemType& searchItem) const

{

int loc;

bool found = false;

for (loc = 0; loc < this->length; loc++)

if (this->list[loc] == searchItem)

{

found = true;

break;

}

if (found)

return loc;

else

return -1;

} //end seqSearch

template <class elemType>

void unorderedArrayListType<elemType>::remove

(const elemType& removeItem)

{

int loc;

if (this->length == 0)

cout << "Cannot delete from an empty list." << endl;

else

{

loc = seqSearch(removeItem);

if (loc != -1)

this->removeAt(loc);

else

cout << "The item to be deleted is not in the list."

<< endl;

}

} //end remove

template <class elemType>

void unorderedArrayListType<elemType>::replaceAt(int location,

const elemType& repItem)

{

if (location < 0 || location >= this->length)

cout << "The location of the item to be "

<< "replaced is out of range." << endl;

else

this->list[location] = repItem;

} //end replaceAt

template <class elemType>

unorderedArrayListType<elemType>::unorderedArrayListType(int size)

: arrayListType<elemType>(size)

{

}

#endif

// unorderedSet.h

#ifndef H_unorderedSet

#define H_ unorderedSet

#include "unorderedArrayListType.h"

template <class elemType>

class unorderedSet : public unorderedArrayListType<elemType>

{

public:

void insertAt(int location, const elemType& insertItem);

void insertEnd(const elemType& insertItem);

void replaceAt(int location, const elemType& repItem);

unorderedSet(int size = 100);

//Constructor

unorderedSet operator+(const unorderedSet &other);

unorderedSet operator-(const unorderedSet &other);

};

template <class elemType>

void unorderedSet<elemType>::insertAt(int location, const elemType& insertItem)

{

               if(unorderedArrayListType<elemType>::seqSearch( insertItem) == -1)

               {

                              unorderedArrayListType<elemType>::insertAt(location,insertItem);

               }

}

template <class elemType>

void unorderedSet<elemType>::insertEnd(const elemType& insertItem)

{

               if(unorderedArrayListType<elemType>::seqSearch( insertItem) == -1)

               {

                              unorderedArrayListType<elemType>::insertEnd(insertItem);

               }

}

template <class elemType>

void unorderedSet<elemType>::replaceAt(int location, const elemType& insertItem)

{

               if(unorderedArrayListType<elemType>::seqSearch( insertItem) == -1)

               {

                              unorderedArrayListType<elemType>::replaceAt(location,insertItem);

               }

}

template <class elemType>

unorderedSet<elemType>::unorderedSet(int size) : unorderedArrayListType<elemType>(size)

{

}

template <class elemType>

unorderedSet<elemType> unorderedSet<elemType>:: operator+(const unorderedSet<elemType> &other)

{

               elemType item;

               int resultMaxSize = this->maxSize + other.maxSize;

               unorderedSet<elemType> result(resultMaxSize);

               for(int i=0;i<this->length;i++)

               {

                              this->retrieveAt(i,item);

                              result.insertEnd(item);

               }

               for(int i=0;i<other.length;i++)

               {

                              other.retrieveAt(i,item);

                              result.insertEnd(item);

               }

               return result;

}

template <class elemType>

unorderedSet<elemType> unorderedSet<elemType>:: operator-(const unorderedSet<elemType> &other)

{

               elemType item;

               int resultMaxSize =0;

               if(this->maxSize > other.maxSize)

                              resultMaxSize = this->maxSize;

               else

                              resultMaxSize = other.maxSize;

               unorderedSet<elemType> result(resultMaxSize);

               for(int i=0;i<this->length;i++)

               {

                              this->retrieveAt(i,item);

                              if(other.seqSearch(item) != -1)

                              {

                                             result.insertEnd(item);

                              }

               }

               return result;

}

#endif

// main.cpp

#include "unorderedSet.h"

#include <iostream>

using namespace std;

int main()

{

               int intArr[] = {12,23,4,7,12,9,10,56,23,11};

               string strArr[] = {"banana","apple","pear","grape","banana","fig","mango","orange","pear","guava"};

               unorderedSet<int> intSet(20);

               for(int i=0;i<10;i++)

                              intSet.insertEnd(intArr[i]);

               unorderedSet<string> strSet(20);

               for(int i=0;i<10;i++)

                              strSet.insertEnd(strArr[i]);

               cout<<"\nInteger Set : "<<intSet<<endl;

               cout<<"String Set : "<<strSet<<endl;

               intSet.insertAt(5,30);

               cout<<"\nInsert At non-duplicate\nInteger Set : "<<intSet<<endl;

               intSet.insertAt(5,11);

               cout<<"Insert At duplicate\nInteger Set : "<<intSet<<endl;

               strSet.replaceAt(1,"pineapple");

               cout<<"\nReplace At non-duplicate\nString Set : "<<strSet<<endl;

               strSet.replaceAt(3,"pear");

               cout<<"Replace At Duplicate\nString Set : "<<strSet<<endl;

               int intArr1[] = {7,0,19,56,22,11,23,5};

               string strArr1[] = {"red","yellow","grape","banana","mango","orange","guava"};

               unorderedSet<int> intSet1(20);

               for(int i=0;i<8;i++)

                              intSet1.insertEnd(intArr1[i]);

               unorderedSet<string> strSet1(20);

               for(int i=0;i<7;i++)

                              strSet1.insertEnd(strArr1[i]);

               unorderedSet<int>unionIntSet = intSet + intSet1;

               cout<<"\nInt Set1 :"<<endl<<intSet<<endl;

               cout<<"Int Set2 :"<<endl<<intSet1<<endl;

               cout<<"Union Int Set : "<<endl;

               cout<<unionIntSet<<endl;

               unorderedSet<int>intersectIntSet = intSet - intSet1;

               cout<<"Intersection Int Set : "<<endl;

               cout<<intersectIntSet<<endl;

               cout<<"\nString Set1 :"<<endl<<strSet<<endl;

               cout<<"String Set2 :"<<endl<<strSet1<<endl;

               unorderedSet<string> unionStrSet = strSet + strSet1;

               unorderedSet<string> intersectStrSet = strSet - strSet1;

               cout<<"Union String Set : "<<endl;

               cout<<unionStrSet<<endl;

               cout<<"Intersection String Set : "<<endl;

               cout<<intersectStrSet<<endl;

               return 0;

}

//end of main.cpp

Output:

Integer Set 12 23 4 7 9 10 56 11 String Set banana apple pear grape fig mango orange guava Insert At non-duplicate Integer Se

Add a comment
Know the answer?
Add Answer to:
This project is divided into 3 parts: Part 1. Create a new project and download the arrayList and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function...

    The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. note: please give all code in c++ below is the class and implementation(a test program would be helpful in determining how to use it): class arrayListType { public:    ...

  • How do I do this? -> string print() const; Function to output the data, return the...

    How do I do this? -> string print() const; Function to output the data, return the output in the form of string, with all elements in the hash table included and each seperated by a space this is my code: template <class elemType> string hashT<elemType>::print() const { for (int i = 0; i < HTSize; i++){        if (indexStatusList[i] == 1){        cout <<HTable[i]<< " " << endl;        }   }    } **********Rest of the code...

  • A. Please explain function studentType(): studentType::studentType() { numberOfCourses = 0; sId = 0; isTuitionPaid = false;...

    A. Please explain function studentType(): studentType::studentType() { numberOfCourses = 0; sId = 0; isTuitionPaid = false; for (inti = 0; i < 6; i++) coursesGrade[i] = '*'; } B. Please explain function arrayListType() and :~arrayListType() arrayListType::arrayListType(int size) { if (size <= 0) { cout << "The array size must be positive. Creating " << "an array of the size 100." << endl; maxSize = 100; } else maxSize = size; length = 0; list = new int[maxSize]; } arrayListType::~arrayListType() {...

  • Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary...

    Write a function, swapSubtrees, that swaps all of the left and right subtrees of a binary tree. Add this function to the class binaryTreeType and create a program to test this function. #include <iostream> using namespace std; //Definition of the Node template <class elemType> struct nodeType { elemType info; nodeType<elemType> *lLink; nodeType<elemType> *rLink; }; //Definition of the class template <class elemType> class binaryTreeType { public: //Overload the assignment operator. const binaryTreeType<elemType>& operator=(const binaryTreeType<elemType>&) { if (this != &otherTree) //avoid self-copy...

  • A. Please explain function below: unorderedArrayListType::unorderedArrayListType(int size) : arrayListType(size) { } B. Please explain function below:...

    A. Please explain function below: unorderedArrayListType::unorderedArrayListType(int size) : arrayListType(size) { } B. Please explain function below: voidunorderedArrayListType::remove(intremoveItem) { int loc; if (length == 0) cout << "Cannot delete from an empty list." << endl; else { loc = seqSearch(removeItem); if (loc != -1) removeAt(loc); else cout << "The item to be deleted is not in the list." << endl; } } C. Please explain function below: What is the output of the following code? int x = 0; int y...

  • //This program is your final exam. //Please fill in the functions at the bottom of the...

    //This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...

  • //This program is your final exam. //Please fill in the functions at the bottom of the...

    //This program is your final exam. //Please fill in the functions at the bottom of the file. (evenCount and insertItem) //DO NOT CHANGE ANYTHING ELSE. //main has all the code needed to test your functions. Once your functions are written, please build and make sure it works fine //Note that in this case, the list is not sorted and does not need to be. Your goal is to insert the number in the given position. #include <iostream> #include <fstream> using...

  • #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool...

    #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...

  • Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo t...

    Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...

  • (C++) Two stacks of the same type are the same if they have the same number...

    (C++) Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same. Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise. Also, write the definition of the function template to overload this operator. Write a program to test the various overloaded operators and functions of classstackType. **Please...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT