Need help on following program using c language Redo followi

Need help on following program using c++ language. Redo following Unordered Sets project using templates. A template for unorderedList is supplied. You should turn in your unorderedSet template and your test program modified to use the template version of unorderedSet.

(Unordered Sets) As explained in this chapter, a set is a collection of distinct elements of the same type. Design the class unorderedSetType, derived from the class  unorderedArrayListType, to manipulate sets. Note that you need to redefine only the functions insertAt, insertEnd, and replaceAt. If the item to be inserted is already in the list, the functions insertAt and insertEnd output an appropriate message. Similarly, if the item to be replaced is already in the list, the function replaceAt outputs an appropriate message.Includethe set operations of union and intersection in your class. Also write a program to test your class.

Here is setType.h

#ifndef SETTYPE_H_INCLUDED

#define SETTYPE_H_INCLUDED

#include \"unorderedArrayListType.h\"

class setType: public unorderedArrayListType

{

public:

bool addSet(int item);

// Adds an item to the set after first making sure that the item is not already in the set

// Returns true if the item has been successfully added, otherwise returns false

bool removeSet(int item);

// Removes an item from the set

// Returns true if the item has been removed from the set, otherwise returns false if the item

// is not part of the set

void unionOp(const setType &otherSet, setType &unionSet);

// Performs the set union operation with otherSet

// Postcondition: the result of the union operation is in unionSet

void intersectOp(const setType &otherSet, setType &intersectSet);

// Performs the set intersection operation with otherSet

// Postcondition: the result of the intersection operation is in intersectSet

setType(int size = 100);

// Constructor

};

#endif // SETTYPE_H_INCLUDED

Here is SetType.cpp

#include <iostream>

#include \"setType.h\"

using namespace std;

bool setType::addSet(int item)

{

bool itemAdded = true;

if (seqSearch(item) == -1)

// item not already in set, ok to add

insertEnd(item);

else

// Can\'t have a duplicate

itemAdded = false;

return itemAdded;

}

bool setType::removeSet(int item)

{

int location;

bool itemRemoved = true;

if ((location = seqSearch(item)) == -1)

// Item not there, can\'t remove

itemRemoved = false;

else

// Remove the item

removeAt(location);

return itemRemoved;

}

void setType::unionOp(const setType &otherSet, setType &unionSet)

{

int item;

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

unionSet.addSet(list[i]);

for (int i=0; i < otherSet.listSize(); i++)

{

item = otherSet.retrieveAt(i);

unionSet.addSet(item);

}

}

void setType::intersectOp(const setType &otherSet, setType &intersectSet)

{

int item;

// Outer loop is the smaller set

if (listSize() < otherSet.listSize())

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

{

item = retrieveAt(i);

if (otherSet.seqSearch(item) > -1)

intersectSet.addSet(item);

}

else

for(int i = 0; i < otherSet.listSize(); i++)

{

item = otherSet.retrieveAt(i);

if (seqSearch(item) > -1)

intersectSet.addSet(item);

}

}

setType::setType(int size)

   : unorderedArrayListType(size)

{

} //end constructor

Solution

Hope this will help-

#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)
{
    cout << \"See Programming Exercise 20.\" << endl;
} //end insertAt

template <class elemType>
void unorderedArrayListType<elemType>::insertEnd
                                 (const elemType& insertItem)
{
    if (length >= maxSize) //the list is full
        cout << \"Cannot insert in a full list.\" << endl;
    else
    {
        list[length] = insertItem; //insert the item at the end
        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 < length; loc++)
        if (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 (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;
    }
} //end remove

template <class elemType>
void unorderedArrayListType<elemType>::replaceAt(int location,
                                       const elemType& repItem)
{
    if (location < 0 || location >= length)
        cout << \"The location of the item to be \"
             << \"replaced is out of range.\" << endl;
    else
        list[location] = repItem;
} //end replaceAt

template <class elemType>
unorderedArrayListType<elemType>::
                       unorderedArrayListType(int size)
                       : arrayListType<elemType>(size)
{
} //end constructor


#endif

Need help on following program using c++ language. Redo following Unordered Sets project using templates. A template for unorderedList is supplied. You should t
Need help on following program using c++ language. Redo following Unordered Sets project using templates. A template for unorderedList is supplied. You should t
Need help on following program using c++ language. Redo following Unordered Sets project using templates. A template for unorderedList is supplied. You should t
Need help on following program using c++ language. Redo following Unordered Sets project using templates. A template for unorderedList is supplied. You should t
Need help on following program using c++ language. Redo following Unordered Sets project using templates. A template for unorderedList is supplied. You should t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site