$29.99
Project 2: PlayList (a very simple one)
It is the good old 1990s, you are in the shower getting ready for work and listening to your favorite album when... the CD starts skipping (CD stands for Compact Disk -- for the very young among you) You are running late, so you just turn off the music, grab your CD player (and a different CD, oh well!) and run off to work. Now you are biking to work, it's a beautiful sunny day and you are listening to your second-favorite album when... you hit a bump in the road and the strap on your CD player becomes loose, your CD player hits the front bar on your bike and your CD goes flying to the other side of the road and
cracks... needless to say it is now useless Oh yes, the 1990s were lovely but could also be very frustrating! But luckily you are the best programmer in town, so when you get to work (clearly you cannot work all day without music!!!) you decide you will code your own PlayList... and your own Songs while you are at it . That way you can keep on listening to music on your computer while you work.
Time to put on your Design hat ... So how are you going to store all those Songs? You remember that in your Software Analysis and Design II class your professor just discussed an new Abstract Data Type, a Bag. Yes, let's just throw all the songs in a Bag and listen to them... except you don't want the same song to play more than once in your playlist. Easy, you just modify the Bag ADT so it does not allow duplicates... but that sounds more like a set rather than a bag! So you call your new ADT Set.
Design a simple PlayList Program
Class Set You are given an interface: SetInterface.h (just like BagInterface.h but it does not allow duplicates) 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 from Bag only in the fact that it does not allow duplicates. This means that it does not have a getFrequencyOf()method because an item can be in the Set only once. 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 <vector
template<class ItemType class SetInterface { public:
9/7/2018 Project2
/** 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; 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.
Class Song
9/7/2018 Project2
You will also code your own Song class, so you can add Songs to your playlist. A Song stores the following information (private member variables):
std::string title_; std::string author_; std::string album_; And the following operations (public member functions)
Song(); Song(const std::string& title, const std::string& author = "", const std::string& album = ""); void setTitle(std::string title); //"set" in setTitle here means "give a value" and has nothing // to do with the Set class. Similarly for setAuthor and setAlbum void setAuthor(std::string author); void setAlbum(std::string album); std::string getTitle() const; std::string getAuthor() const; std::string getAlbum() const; friend bool operator==(const Song& lhs, const Song& rhs); Since you are the best programmer in town I trust you will do a great job at commenting these thoroughly!!!
Class PlayList 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;
You will notice that the Set ADT did serve you well. Most of the things you want to do to your PlayList are functionalities your Set ADT provides, so all of these functions will essentially be making calls to the corresponding Set public members... good design goes a long way!!! Once again, since you are the best programmer in town I trust you will do a great job at commenting these thoroughly!!! A few things to notice: The parameterized constructor needs to add a_song to playlist_ Depending on your design/implementation, when removing an item, Set may or may not have preserved an order for the remaining items because in a Set THERE IS NO ORDER. In a PlayList, on the other hand, you may like to have Songs play in a certain order. Don't worry about that for now, although it may not be the most desirable behavior, you can simply remove a Song from the PlayList by calling the Set::remove() member function no matter how you implemented it. We will take care of this in Project 3. displayPlayList() will take advantage of Set::toVector() to access and display to the console (cout) data for all the songs in playlist_ . For each song it will display: * Title: title * Author: author * Album: album * on a new line, where the text in red should be replaced by the value of the corresponding Song member variable. After displaying data for all the songs it will display: End of playlist on a new line.
Usage:
9/7/2018 Project2
Make sure your code compiles and runs correctly with this main() function:
int main() { //**********Test Song************// //instantiate 5 songs Song song1; song1.setTitle("title 1"); song1.setAuthor("author 1"); song1.setAlbum("album 1"); Song song2("title 2", "author 2", "album 2"); Song song3("title 3", "author 3", "album 3"); Song song4("title 4", "author 4", "album 4"); Song song5("title 5", "author 5", "album 5"); //output song information
cout << "The first song is: " << song1.getTitle() << ", " << song1.getAuthor() << ", " << song1.getAlbum() << endl; cout << "The second song is: " << song2.getTitle() << ", " << song2.getAuthor() << ", " << song2.getAlbum() << endl; cout << "The third song is: " << song3.getTitle() << ", " << song3.getAuthor() << ", " << song3.getAlbum() << endl; cout << "The fourth song is: " << song4.getTitle() << ", " << song4.getAuthor() << ", " << song4.getAlbum() << endl << endl; //************* Test PlayList*************// //instantiate PlayList and add Songs to it PlayList myPlayList(song1); myPlayList.addSong(song2); myPlayList.addSong(song3); myPlayList.displayPlayList(); cout << "Playlist now holds " << myPlayList.getNumberOfSongs() << " songs\n\n"; myPlayList.addSong(song1); myPlayList.displayPlayList(); cout << endl; myPlayList.addSong(song4); myPlayList.displayPlayList(); cout << endl; myPlayList.addSong(song5); myPlayList.displayPlayList(); cout << endl; myPlayList.removeSong(song2); myPlayList.displayPlayList(); cout << endl; myPlayList.removeSong(song3); myPlayList.displayPlayList(); cout << endl; myPlayList.clearPlayList(); myPlayList.displayPlayList(); cout << myPlayList.isEmpty() << endl; return 0; }
9/7/2018 Project2
The task:
For this project you are given the full class interface SetInterface.h that your Set class will inherit from. You are also given as a sample usage main() function. This is the function that will be used by Gradescope to test your code. You need to write and submit 3 classes (6 files: Set.h, Set.cpp, Song.h, Song.cpp, PlayList.h, PlayList.cpp)
Submission:
Your project must be submitted on Gradescope. The due date is September 25 by 9pm. Feel free to submit early!!! Multiple submissions are allowed, only the last submission will be graded. No late submissions will be accepted. Submit Set.h, Set.cpp, Song.h, Song.cpp, PlayList.h, PlayList.cpp (6 files) ONLY. Your code will be tested with the above main function for grading, so make sure your code runs without problems with the above main function on the machines in the Linux lab. Your files should include a preamble comment with the following information: file name, your name, date, assignment (e.g. CSCI 235, Fall 2018, Project 1) and a brief description. All functions should have a comment preamble including a description, as well as pre, post conditions and return when appropriate. Feel free to use the same preamble you write in the interface for each corresponding method in the implementation.
Phew!!! You finally have your music back, now you can get to work. Have Fun!!!!!
9/7/2018 Project2