Question: c++ Please create Set.cpp and Set.h The following information is needed (setinterface.h) Class Set You are given an interface: SetInterfac This is a public interface
c++
Please create Set.cpp and Set.h
The following information is needed (setinterface.h)
Class Set
You are given an interface: SetInterfac This is a public interface and completely specifies what the Set class operations must be. SetInterface is an abstract class (it has no implementation), so your Set class must inherit from SetInterface and implement all of its methods. Set differs in the fact that it does not allow duplicates. This also means that add()must check that an element is not in Set already if it is the item will not be added.
Here is the SetInterface: __________________________________________________________________________________
#ifndef SET_INTERFACE_H_
#define SET_INTERFACE_H_
#include
template
class SetInterface
{
public:
/** Gets the current number of entries in this set.
@return The integer number of entries currently in the set. */
virtual int getCurrentSize() const = 0;
/** Checks 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& newEntry) = 0;
/** Removes 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 entry to be removed.
@return True if removal was successful, or false if not. */
virtual bool remove(const ItemType& anEntry) = 0;
/** Removes all entries from this set.
@post set contains no items, and the count of items is 0. */
virtual void clear() = 0;
/** Tests whether this set contains a given entry.
@param anEntry The entry to locate.
@return True if set contains anEntry, or false otherwise. */
virtual bool contains(const ItemType& anEntry) const = 0;
/** Fills a vector with all entries that are in this set.
@return A vector containing all the entries in the set. */
virtual std::vector
}; // end SetfInterface
#endif /* SET_INTERFACE_H_ */
______________________________________________________________________________________________________
Other than the methods specified by the SetInterface, your Set class, similarly to the Bag class, will also have some private data members:
static const int DEFAULT_SET_SIZE = 4; // for testing purposes we will keep the set small
ItemType items_[DEFAULT_SET_SIZE]; // array of set items
int item_count_; // current count of set items
int max_items_; // max capacity of the set
Set also has a private member function (a helper function) other than the public methods specified by SetInterface.h It is used by some of its' public methods to find out where a particular item is
// post: Either return the index of target in the array items_
// or -1 if the array does not contain the target
int getIndexOf(const ItemType& target) const;
Remember, Set is an Abstract Data Type! Since you are doing the work, you want to make it as general as possible... you may need to implement film streaming software tomorrow if something goes wrong with your television set So Set is templated and can store an arbitrary ItemType.
So please write code for two files Set.cpp (implementation) and Set.h(interface)
If you would write a main function to show that it works. That would be great. But please following the directions for the set class.
Thank you so much.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
