Project 2

Due: Sunday June 19th, (11:59 PM) (15 Extra Credit for Submitting by Thursday June, 16th -- 10 project / 5 Midterm)

Objective

This assignment will give you practice with:

Task

You will be writing a class that represents a play list of songs. Your play list class will manage a dynamically allocated array of song objects. The Song class is provided for you:
song.h
song.cpp

You should not change these files. I will test your programs using these originals.

You will write a class called PlayList implemented in files playlist.h and playlist.cpp.

Your PlayList class will support two basic uses:

Program Details and Requirements:

There is no size limit on the play list, so it should be implemented with a dynamically allocated array. There should never be more than 5 unused slots in the array (ie the number of allocated spaces may be at most 5 larger than the number of slots that are actually filled with real data. Whenever the array is resized, print a message (for testing purposes) that states that the array is being resized, and what the new size is. Example: "** Array being resized to 10 allocated slots **". Correct memory management should be used, including the cleanup of memory (i.e. you must program the class so that it leaves no "memory leaks"). This means that you need to deallocate any dynamic space, when and where appropriate.

Your class must provide the following member functions:
  1. AddSong
    This function will take a Song object as a parameter and insert it into the play list.

  2. DeleteSong
    This function will take a Song object as a parameter and search the play list for it. If it is found, it should be removed and the function should return true. If it is not found, a value of false should be returned. If the play list has multiple copies of one song, you should just delete all copies.

  3. Intersect
    This function will take a Playlist object as a parameter and return a new playlist that is the intersection of the songs in the playlist argument (the playlist passed in by the caller) and the songs contained within the playlist object in which Intersect been called (calling object). That is, the new playlist will contain all songs that are common to both playlists (with no duplicates).

  4. ShowAll
    This function will print all of the songs in the play list to the screen.

  5. SetMode
    This function will change the playing mode of the play list. Your class will have to keep track of the playing mode and the song that is currently being played. The three modes are:


    Mode Meaning
    NORMAL After playing this song, the next song to be played is the next sequential song. For example after playing song with index 7, the next song to be played is the song at index 8. If the last song is played, the next song should be song 0.
    REPEAT After playing this song, the next song to be played will still be this song.

    The mode should be defined with the following enumeration in your playlist.h file:
    enum Mode
    {
      NORMAL,
      REPEAT
    };

  6. Play
    This function will play one song from the play list. This simply involves printing a message along with the song name. The first time the Play function is called, it should play the song at index 0. Later calls should play other songs depending on the current mode.


Your class must also overload the following operators and implement the described functionality accordingly:
  1. Addition operator (+)
    The addition operator will have two meanings depending on the arguments supplied by the caller:
  2. Subtraction operator (-)
    The subtraction operator will have only one meaning:
In addition to these functions, your class must provide any other functions that are needed to ensure that the memory handling is safe and correct. Your class should not produce memory leaks or segmentation faults under any circumstances!

Test Program

I've created a menu program that will help you interactively test the features of your PlayList class. You can get a copy of menu.cpp here.

This program will allow you to interactively test the features of your PlayList class. Keep in mind that this program does not test everything that your class must handle. For example, it doesn't test the copy constructor or the operator overloads. You should write other tests that verify you are implementing your memory allocation and deallocation correclty.

General Requirements:

Hints:

For Project 2, submit the following files via PyGrader:
 
  playlist.h
  playlist.cpp