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

******URGENT******: Hello, please help in C++ please do not reply with code from

ID: 3599648 • Letter: #

Question

******URGENT******:

Hello, please help in C++

please do not reply with code from other questions since they dont work, a working code is needed.

PREVIOUS IMPLEMENTATION:

//arrayListType.cpp

#include

#include "arrayListType.h"

using namespace std;

bool arrayListType::isEmpty() const {

   return (length == 0);

} //end isEmpty

bool arrayListType::isFull() const {

   return (length == maxSize);

} //end isFull

int arrayListType::listSize() const {

   return length;

} //end listSize

int arrayListType::maxListSize() const {

   return maxSize;

} //end maxListSize

void arrayListType::print() const {

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

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

   cout << endl;

} //end print

bool arrayListType::isItemAtEqual(int location, int item) const {

   if (location < 0 || location >= length) {

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

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

       return false;

   }
   else

       return (list[location] == item);

} //end isItemAtEqual

void arrayListType::removeAt(int location) {

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

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

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

   else {

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

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

       length--;

   }

} //end removeAt

void arrayListType::retrieveAt(int location, int& retItem) const {

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

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

       << "out of range" << endl;

   else

       retItem = list[location];

} //end retrieveAt

void arrayListType::clearList() {

   length = 0;

} //end clearList

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

} //end constructor

arrayListType::~arrayListType() {

   delete[] list;

} //end destructor

arrayListType::arrayListType(const arrayListType& otherList) {

   maxSize = otherList.maxSize;

   length = otherList.length;

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

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

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

}//end copy constructor

//arrayListType.h

class arrayListType
{
public:
   bool isEmpty() const;
   bool isFull() const;
   int listSize() const;
   int maxListSize() const;
   void print() const;
   bool isItemAtEqual(int location, int item) const;
   virtual void insertAt(int location, int insertItem) = 0; //redefine
   virtual void insertEnd(int insertItem) = 0; //redefine
   void removeAt(int location); //redefine
   void retrieveAt(int location, int& retItem) const;
   virtual void replaceAt(int location, int repItem) = 0;
   void clearList();
   virtual int seqSearch(int searchItem) const = 0;
   virtual void remove(int removeItem) = 0;
   arrayListType(int size = 100);
   arrayListType(const arrayListType& otherList);
   virtual ~arrayListType();
protected:
   int *list;
   int length;
   int maxSize;

};

//unorderedArrayListType.h

#ifndef UNORDEREDARRAYLISTTYPE_H

#define UNORDEREDARRAYLISTTYPE_H

#include "arrayListType.h"

class unorderedArrayListType : public arrayListType {

public:
   void insertAt(int location, int insertItem);
   void insertEnd(int insertItem);
   void replaceAt(int location, int repItem);
   int seqSearch(int searchItem) const;
   void remove(int removeItem);
   void removeAll(int removeItem);
   unorderedArrayListType(int size = 100);

};
#endif

//unorderedArrayListType.cpp

#include

#include "unorderedArrayListType.h"

using namespace std;

void unorderedArrayListType::insertAt(int location,

   int insertItem) {

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

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

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

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

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

   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 specified position

       length++; //increment the length

   }

} //end insertAt

void unorderedArrayListType::insertEnd(int 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

int unorderedArrayListType::seqSearch(int searchItem) const {

   int loc;

   bool found = false;

   loc = 0;

   while (loc < length && !found)

       if (list[loc] == searchItem)

           found = true;

       else

           loc++;

   if (found)

       return loc;

   else

       return -1;

} //end seqSearch

void unorderedArrayListType::remove(int 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

void unorderedArrayListType::removeAll(int removeItem) {

   int loc;

   if (length == 0)

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

   else {

       // Find and remove the first occurrence of removeItem (if there is one)

       loc = seqSearch(removeItem);

       if (loc != -1)

           removeAt(loc);

       else

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

   }

   // Set up a loop to find other occurrences and delete them as well

   while (loc != -1)

   {

       loc = seqSearch(removeItem);

       if (loc != -1)

           removeAt(loc);

   }

}

void unorderedArrayListType::replaceAt(int location, int 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

unorderedArrayListType::unorderedArrayListType(int size)

   : arrayListType(size) {

} //end constructor

//unorderedSetType.h

#ifndef UNORDEREDSETTYPE_H
#define UNORDEREDSETTYPE_H

#include "unorderedArrayListType.h"

class unorderedSetType : public unorderedArrayListType {
public:

   void insertAt(int location, int insertItem);
   // Function to insert an item at a particular location
   // Postcondition: The item has been added to the list and the length has
   // been increased by 1.

   void insertEnd(int insertItem);
   // Function to insert an item at the end of the list
   // Postcondition: The item has been added at the end of the list and the
   // length has been increased by 1.

   void replaceAt(int location, int repItem);
   // Function to replace an item in the list.
   // Postcondition: repItem overrwrites the item at the specified location
   // in the list. The length of the list is unchanged.

   unorderedSetType setUnion(unorderedSetType set);
   //returns a new set containing members of caller and parameter

   unorderedSetType setIntersect(unorderedSetType set);
   //returns a new set containing only members parameter and caller share.

   unorderedSetType(int size = 100);
   //constructor


};

#endif /* UNORDEREDSETTYPE_H */

THANK YOU.

Problem (Ordered Sets) Programming Exercise 12 asks you to define the class unorderedSetType to manipulate sets. The elements of an unorderedSetType object are distinct, but in no particular order.Design the class orderedSetType, derived from the class orderedArrayListType, to manipulate ordered sets. The elements of an orderedSetType object are distinct and in ascending order. Note that you need to redefine only the functions insert and replaceAt. If the item to be inserted is already in the list, the function insert outputs an appropriate message Similarly, if the item to be replaced is already in the list, the function replaceAt outputs an appropriate message. Also, write a program to test your class Reference (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. Also, write a program to test your class

Explanation / Answer

Given below is the implementation for unorderedSetType.cpp and also a test program for the same.

compile using :  g++ arrayListType.cpp unorderedArrayListType.cpp unorderedSetType.cpp test.cpp

In case of any issues, let me know through comments, I will help. If the answer helped, please don't forget to rate it. Thank you.

unorderedSetType.cpp


#include "unorderedSetType.h"
#include <iostream>
using namespace std;
void unorderedSetType::insertAt(int location, int insertItem)
{
if(seqSearch(insertItem) == -1) //check if its not present
unorderedArrayListType::insertAt(location, insertItem);
else
cout << "Can't insert. " << insertItem << " is already in set" << endl;
}
// Function to insert an item at a particular location
// Postcondition: The item has been added to the list and the length has
// been increased by 1.
void unorderedSetType::insertEnd(int insertItem)
{
if(seqSearch(insertItem) == -1) //check if its not present
unorderedArrayListType::insertEnd(insertItem);
else
cout << "Can't insert. " << insertItem << " is already in set" << endl;
}
// Function to insert an item at the end of the list
// Postcondition: The item has been added at the end of the list and the
// length has been increased by 1.
void unorderedSetType::replaceAt(int location, int repItem)
{
if(seqSearch(repItem) == -1) //check if repItem is not present, then only replace
unorderedArrayListType::replaceAt(location, repItem);
else
cout << "Can't replace. " <<repItem << " is already in set." << endl;
}
// Function to replace an item in the list.
// Postcondition: repItem overrwrites the item at the specified location
// in the list. The length of the list is unchanged.
unorderedSetType unorderedSetType::setUnion(unorderedSetType other)
{
unorderedSetType result(*this); //first put all elements from this set into result
  
// now put only those from other that are not duplicate into result
for(int i = 0; i < other.length; i++)
{
if(result.seqSearch(other.list[i]) == -1) //if not duplicate
result.insertEnd(other.list[i]);
}
return result;

}
//returns a new set containing members of caller and parameter
unorderedSetType unorderedSetType::setIntersect(unorderedSetType other)
{
unorderedSetType result;
  
// for each element in this set, check if the elemetn is also present in other, then only add it to result
for(int i = 0; i < length; i++)
{
if(other.seqSearch(list[i]) != -1) //if present in other set also
result.insertEnd(list[i]);
}
return result;
}
//returns a new set containing only members parameter and caller share.
unorderedSetType::unorderedSetType(int size):unorderedArrayListType(size)
{
  
}
//constructor

test.cpp

#include "unorderedSetType.h"
#include <iostream>
using namespace std;
int main()
{
unorderedSetType s1, s2;
cout << "s1: insertEnd 1 3" << endl;
s1.insertEnd(1);
s1.insertEnd(3);
cout <<"s1: insertAt(0, 5)" << endl;
s1.insertAt(0,5);
cout << "s1 contains " ;
  
cout << "s2: insertEnd 2 3" << endl;
s2.insertEnd(2);
s2.insertEnd(3);
cout <<"s2: insertAt(0, 6)" << endl;
s2.insertAt(0,6);
cout << "s2 contains " ;
s2.print();
  
s2.replaceAt(1, 3);// replace should not work, since s2 already has 3
  
unorderedSetType s3 = s1.setIntersect(s2);
unorderedSetType s4 = s1.setUnion(s2);
  
cout << "intersection of s1 and s2 : " ;
s3.print();
cout << "union of s1 and s2 : " ;
s4.print();
  
}

output

s1: insertEnd 1 3
s1: insertAt(0, 5)
s1 contains s2: insertEnd 2 3
s2: insertAt(0, 6)
s2 contains 6 2 3
Can't replace. 3 is already in set.
intersection of s1 and s2 : 3
union of s1 and s2 : 5 1 3 6 2