For my third assignment in CS2, I was given the following:A set is a special bag that does not allow duplicates. Specify each  operation for a set of objects by stating its purpose, by describing  its parameters, and by writing preconditions, postconditions, and a  pseudocode version of its header. Then write a C++ interface for the  set. Include javadoc-style comments in your code.The difference of two bags is a new bag containing the entries that  would be left in one bag after removing those entries that also  occur in the second set. Design and specify a method difference() for  the ADT bag that returns as a new bag the difference of the bag  receiving the call to the method and the bag that is the method's one  argument. Include sufficient comments to fully specify the method.Not too much to say, looking for a more efficient way to implement this perhaps.  Feel free to rip it apart!SetInterface.h:#ifndef SET_INTERFACE#define SET_INTERFACE#include <vector>/** @class BagInterface BagInterface.h BagInterface.h * *  Definition of BagInterface class template. */template <typename ItemType>class SetInterface {public:  /** Virtual destructor. */  virtual ~SetInterface() {}  /** Gets the current number of entries in this set.   *  @return The integer number of entries currently in the set.    */  virtual int size() const = 0;  /** Gets the maximum number of items allowed in a set   *  @return The integer number of maximum items allowed in a set   */  virtual int getCapacity() const = 0;  /** Sets the maximum number of items allowed in a set   *  @post The capacity memeber of the Set instance will be set to    *        whatever number was passed in   *  @param num The maximum number of items that can be stored in a set   */  virtual void setCapacity(int) = 0;  /** Sees whether this set is empty.   *   *  @return True if the set is empty, or false if not.    */  virtual bool isEmpty() const = 0;  /** Adds a new entry to this set.   *   *  @post If successful, newEntry is stored in the set and the   *        count of items in the set has increased by 1.   *   *  @param newEntry The object to be added as a new entry.   *   *  @return True if addition was successful, or false if not.    */  virtual bool add(const ItemType&) = 0;  /** Removes one occurrence of a given entry from this set, if   *  possible.   *   *  @post If successful, anEntry has been removed from the set and   *        the count of items in the set has decreased by 1.   *   *  @param anEntry The value of the entry to be removed.   *   *  @return True if removal was successful, or false if not.    */  virtual bool remove(const ItemType&) = 0;  /** Removes all entries from this set.   *   *  @post This set contains no items (thus the count is 0).    */  virtual void clear() = 0;  /** Counts the number of times a given entry appears in set.   *   *  @param anEntry The value of the entry to be counted.   *   *  @return The number of times anEntry appears in this set.    */  virtual int count(const ItemType&) const = 0;  /** Tests whether this set contains a given entry.   *   *  @param anEntry The value of the entry to locate.   *   *  @return True if this set contains anEntry, or false   *          otherwise.    */  virtual bool contains(const ItemType&) const = 0;  /** Converts this set into a vector.   *   *  @return A vector containing all the entries in this set.    */  virtual std::vector<ItemType> toVector() const = 0;};#endifSet.cpp:template <typename ItemType>Set<ItemType>::Set() : itemCount(0), capacity(DEFAULT_CAPACITY) {}template <typename ItemType>int Set<ItemType>::size() const {  return itemCount;}template <typename ItemType>int Set<ItemType>::getCapacity() const {  return capacity;}template <typename ItemType>void Set<ItemType>::setCapacity(int num){  capacity = num;}template <typename ItemType>ItemType* Set<ItemType>::getItems(){  return items;}template <typename ItemType>bool Set<ItemType>::isEmpty() const {  return itemCount == 0;}template <typename ItemType>bool Set<ItemType>::add(const ItemType& newEntry) {  int location = -1;  if (itemCount < capacity)   {      for(int i = 0; i < capacity; ++i)      {      if(items[i] == newEntry) return false;      if(location == -1 && items[i] == ItemType{}) location = i;       }      items[location] = newEntry;      ++itemCount;      return true;  }  return false;}template <typename ItemType>bool Set<ItemType>::remove(const ItemType& anEntry) {  int locatedIndex = getIndexOf(anEntry);  bool canRemoveItem = !isEmpty() && locatedIndex > -1;  if (canRemoveItem) {    --itemCount;    items[locatedIndex] = items[itemCount];  }  return canRemoveItem;}template <typename ItemType>void Set<ItemType>::clear() {  itemCount = 0;}template <typename ItemType>bool Set<ItemType>::contains(const ItemType& anEntry) const {  bool found = false;  int curIndex = 0;  while (!found && curIndex < itemCount) {    if (anEntry == items[curIndex]) {      found = true;    }    ++curIndex;  }  return found;}template <typename ItemType>int Set<ItemType>::count(const ItemType& anEntry) const {  int frequency = 0;  int curIndex = 0;  while (curIndex < itemCount) {    if (items[curIndex] == anEntry) {      ++frequency;    }    ++curIndex;  }  return frequency;}template <typename ItemType>Set<ItemType> Set<ItemType>::difference(Set<ItemType> &set) const{  Set<ItemType> newSet;  ItemType *items1 = set.getItems();  for(int i = 0; i < size(); ++i)  {      for(int j = 0; j < set.size(); ++j)      {      if (items[i] == items1[j]) break;      if (j == set.size() - 1) newSet.add(items[i]);      }  }  return newSet;}template <typename ItemType>std::vector<ItemType> Set<ItemType>::toVector() const {  std::vector<ItemType> setContents;  for (int i = 0; i < itemCount; ++i) {    setContents.push_back(items[i]);  }  return setContents;}template <typename ItemType>int Set<ItemType>::getIndexOf(const ItemType& target) const {  bool found = false;  int result = -1;  int searchIndex = 0;  while (!found && searchIndex < itemCount) {    if (items[searchIndex] == target) {      found = true;      result = searchIndex;    }    else {      ++searchIndex;    }  }  return result;}Set.h:#ifndef SET_ADT#define SET_ADT#include SetInterface.h/** @class Set Set.h Set.h * *  Specification of an array-based ADT set. */template <typename ItemType>class Set : public SetInterface<ItemType>{ private:  /** Maximum capacity of this bag. */  static const int DEFAULT_CAPACITY = 6;  /** Number of items in this bag. */  int itemCount;  /** Maximum capacity of this bag. */  int capacity;  /** Data storage. */  ItemType items[DEFAULT_CAPACITY];  /** Gets the index of target in the array 'items' in this bag.   *   * @param target The ItemType value to retrieve the index of.   *   * @return The index of the element in the array 'items' that   *         contains 'target' or -1 if the array does not contain   *         'target'. */  int getIndexOf(const ItemType& target) const;public:  /** Default constructor. */  Set();  int size() const;  int getCapacity() const;  void setCapacity(int);  ItemType* getItems();  bool isEmpty() const;  bool add(const ItemType&);  bool remove(const ItemType&);  void clear();  int count(const ItemType&) const;  bool contains(const ItemType&) const;  Set<ItemType> difference(Set<ItemType>&) const;  std::vector<ItemType> toVector() const;};#include Set.cpp#endifmain.cpp:/** @file main.cpp * *  @course CS1521 *  @section 1 * *  Testing the Set class. */#include <cassert>#include <iostream>#include <string>#include <cstdlib>#include Set.hvoid displaySet(Set<std::string>& set) {        std::cout << The set contains  << set.size() <<  items: << std::endl;    std::vector<std::string> setItems = set.toVector();      int numberOfEntries = (int)setItems.size();    for (int i = 0; i < numberOfEntries; ++i)     {      std::cout << setItems[i] <<  ;    }      std::cout << std::endl;}void setTester(Set<std::string>& set){    assert(1 == set.isEmpty());    displaySet(set);    std::string items[] = {one, two, three, four, five, one};    std::cout << Adding 6 items to the set << std::endl;    for (int i = 0; i < set.getCapacity(); ++i)     {        set.add(items[i]);    }    displaySet(set);    std::cout << Now running tests on the set! << std::endl;    assert(0 == set.isEmpty());    assert(5 == set.size());    assert(6 == set.getCapacity());    assert(0 == set.add(one));    assert(1 == set.add(more));    assert(0 == set.add(extra));    displaySet(set);    std::cout << Testing differences of sets, with set 2 containing \one\ << std::endl;    Set<std::string> set2;    set2.add(one);    Set<std::string> diff = set.difference(set2);    displaySet(diff);    assert(6 == set.size());    assert(6 == set.getCapacity());    assert(1 == set.contains(three));    assert(0 == set.contains(ten));    assert(1 == set.count(one));    assert(1 == set.remove(one));    assert(0 == set.count(one));    assert(0 == set.remove(one));    assert(0 == set.count(one));    std::cout << After clearing the set:  << std::endl;    set.clear();    displaySet(set);    assert(1 == set.isEmpty());    assert(0 == set.contains(two));}int main() {        Set<std::string> set;    std::cout << Testing Set: << std::endl;    setTester(set);        std::cout << All done! << std::endl;}
Set your expectations low for this ADT
c++;c++11;homework;template;set
Overall design:SetInterface is unnecessary. Defining an interface just for the sake of hiding private data & methods might be popular in Java and such languages that rely heavily on dynamic dispatch, but not so much in C++. Your interface makes the code a lot more complicated, from a maintenance standpoint, and spread-out through at least three files. It will also add a virtual table to your class, which has a performance impact and increases the size of the compiled binary. My advice it to just throw away SetInterface and keep a simple and straightforward Set<T> template class.Other details:Your main header comment is outdated:/** @class BagInterface BagInterface.h BagInterface.h   *   * Definition of BagInterface class template. */You are not calling you class/header-file BagInterface.I'd suggest to keep parameter names in function/method prototypes, as this adds to the documentation of the code.Template parameter name for types is by convention just T, though ItemType is also quite descriptive.toVector() can be optimized to avoid vector reallocations by simply declaring the vector with itemCount size:std::vector<ItemType> setContents(itemCount); // <-- Allocate storage just oncefor (int i = 0; i < itemCount; ++i) {    setContents.push_back(items[i]);}However, you can also construct the vector from a range, so that loop can actually be consolidated into a single line:std::vector<ItemType> setContents(items, items + itemCount);Take a look at the Rule of Three. This rule is basically about how your class is going to behave regarding copy via operator = and copy constructors. You might wish to provide custom ones or even completely disallow copy and/or assignment.