Can you help me with Setinterface.cpp and playlist.cpp #ifndef SET_INTERFACE_H_
ID: 3747771 • Letter: C
Question
Can you help me with Setinterface.cpp and playlist.cpp
#ifndef SET_INTERFACE_H_
#define SET_INTERFACE_H_
#include <vector>
template<class ItemType>
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<ItemType> toVector() const = 0;
}; // 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 returns the index of target in the array items_
// or -1 if the array does not contain the target
int getIndexOf(const ItemType& target) const;
Your PlayList class will have a single data member (private member variable), a Set object called playlist_ which will store your Songs:
Set<Song> playlist_;
Your PlayList will have the following operations (public member functions)
PlayList();
PlayList(const Song& a_song);
int getNumberOfSongs() const;
bool isEmpty() const;
bool addSong(const Song& new_song);
bool removeSong(const Song& a_song);
void clearPlayList();
void displayPlayList() const;
Explanation / Answer
Let's see!
You want to figure out things and write functions for that. Correct me if I'm wrong here.
1. If you're using an STL set set.size() should return you the size of the set.
2. To check for empty sets what you need is that set.size() should be 0. So, you can use and if condition to check for the size.
3. set.insert() will allow you to add elements to the set.
4. set.size() will increase by 1 as soon as you add an element into the set
5.
1. set.erase(position)
To remove elements from the set you can use the above mentioned erase() function from STL.
6. To remove all the entries from the set, use set.clear()
7. To check if a set has elements or not you simply check if set.size()>1
If the size is greater than 1, it implies the se is non-empty.
So, these are the things that I thought you'd require in your process of completion of the required tasks.
Hope these help :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.