This assignment demonstrates a queue implemented as a special case of a linked list and how the queue can be managed from an object oriented design perspective.
Create an MP3Player application that maintains a list of songs. The song information must be encapsulated in a class called Song. The following code should be the contents of your Song.h file (be sure to add comment headers to all code in your project):
The application must use a linked list implemented as a queue to hold all the songs in memory. You can use the exact same linked list that you created in a previous assignment! They are given here again for your convenience. Your program must use this code for full credit. Instead of the Node and LinkedList member pointers pointing to Star objects as they did in assignment 3, they will point to Song objects in this assignment. Note that there is a new property of the Node class, prev_, and a new method in the LinkedList class, RemoveThisLink. Note that delete should never be called on a void pointer. The data pointer returned by RemoveThisLink must be cast to a Song pointer outside of the Node and LinkedList classes. Then it must be deleted. Remember the LinkedList and Node classes are not supposed to know anything about the Song class.
A memory picture of these three constructs (Song class, LinkedList class, and the Node struct) is shown below. The Node objects are contained in the linked list. The LinkedList class can directly access the first and last entries in the list. The data_ property of the Node class is of type void*, which means it can contain the address of any type of object. You are going to store the address of Song objects in them. As you can see, there is one Node object associated with each Song object. So for each song that your program reads in from a file or gets from the console, it must create a new Song object and a new Node object (just as in assignment 3).
This application must display a console menu that looks like this:
Please make a selection:
a) Open a song file
b) Add a song
c) Delete a song
d) Play a song
e) Print all songs
When a) is selected, the program must prompt the user to enter a file path for an input song list file. It should open the file and read the data for each song from the file one at a time. Note that each song is on a line by itself and includes the full path, such as:
C:tempACDC – Shook You All Night Long.mp3
For each song, it should dynamically create a Song object (using new), store the song data into the object, and add that object to the linked list (which means it must dynamically create a Node object as well). A song list file is provided and is called songList.txt. It is preset with some random mp3 file paths and is an example only. You must update that file with your own songs. Use the correct path and file names for where your mp3 files are located.
Note that your code must be able to handle any path and filenames, including those with embedded spaces, periods, or other characters. Also, your code should be able to handle random spaces and blank lines in the song list file.
when a) is selected a second time, the program must delete every link in the list before reading the new song catalog file. Remember that the Song and the Node objects must be deleted using the delete keyword. The Node object is deleted in the LinkedList class and the Song object must be deleted in the main file (outside of the LinkedList or Node classes).
Note that if b), c), or d) are selected before a file is loaded, print an error message stating that a file must be loaded first, then print the menu again.
The b) option should prompt the user to enter the full path for a new song. The program must dynamically create a Song object (using new), store the path into the object, and add that object to the linked list. The LinkedList class must create a Node object to store the Song object as a void pointer). The program must append the full path to the same song file.
The c) option should prompt the user to input a song title, without the path, at the console and then check if that song exists in the linked list. If found, that song should be deleted from the linked list and from the file. This is why the prev_ property was added to the Node class. In order to delete a node from the middle of the list, the next_ pointer of the previous node must point to the node after the one being deleted. The prev_ pointer allows the previous node to be accessed. Make sure you don’t have any memory leaks when deleting the node. For every execution of a new statement there must be an execution of a delete statement.
The d) option should prompt the user to input a song title without the path. The program should search for the specified song in the linked list and then print to the screen the string “Currently playing SongName XX”, where SongName is the specified song and XX is the lowest 8 bits of the 2’s complement of the sum of the ASCII characters in the song name. If the song is not found the program should print “That song is not in the songlist”.
The first step is to add the ASCII values of all the characters in the stored song full path and name, including spaces. Store the sum value in an unsigned int type variable. Next, compute the two’s complement of the sum.
The two’s complement can be computed by flipping all the bits of the number and then adding one. To flip a bit means to change it to the opposite value. If it is a 1, flipping it makes it a 0 and vice versa. Flipping the bit pattern 0110 yields 1001. Bits can be flipped using the exclusive OR operator. In C/C++, this is represented by the caret symbol, ^. Exclusive ORing the sum by all 1s (0xFFFFFFFF in hex notation) has the effect of flipping all the bits.