Question
You are working for a company developing a playlist application for music. The user will be able to do such things as: append a song
You are working for a company developing a playlist application for music. The user will be able to do such things as:
append a song at the end of the playlist
insert a song after another song
delete a song
goto a song
play forward from current position
play in reverse order from the current position
etc.
The application designers have decided to make use of a doubly linked list for the playlist data structure. Your job is to implement a doubly linked list (DLL) in C++ to store the playlist based on the provided design. You may not use a library for the doubly linked list (e.g. STL). The DLL will store the names of songs as strings, in the order they are to be played. Use the string class in the STL. The DLL must also implement the notion of a current position in the list.
In addition, you will write the code to parse and execute the playlist commands. The application program will read from standard input and write to standard output. Redirection may be used to do file I/O. A song is "played" by printing the title of the song, followed by a newline. Your program will be compiled and tested automatically by a script, so do not deviate from the assignment specifications. The DLL class should not print anything. You may assume the input will be well formed, in that the command will be the first word, separated from the song title with a space, and ending with a newline.
The commands are as follows, one per line in the input, where
appendSong
insertBefore
The current song is now the newly inserted song.
insertAfter
The current song is now the newly inserted song.
gotoFirstSong
The current song is the first song in the playlist if there is one.
gotoLastSong
The current song is the last song in the playlist if there is one.
playCurrent
Plays (prints) the current song if there is one.
removeSong
Removes the first occurrence of
The new current song is the one following
else it is the one prior to
else there are no longer any songs in the playlist.
If
gotoSong
Set the current song to the first occurrence of
nextSong
Moves the current position to the next song, if one exists, otherwise the current song is unchanged.
prevSong
Moves the current position to the previous song, if one exists, otherwise the current song is unchanged.
playForward
Play (print) songs beginning with the song at the current position, and continuing through the playlist in the forward direction until the last song in the list has been played.
The last song is the new current song.
playReverse
Play (print) songs beginning with the song at the current position, and continuing through the playlist in the reverse direction until the first song in the list has been played.
The first song is the new current song.
quit
Program terminates (do not call exit(), just return).
Don't forget, everything about Unix is case-sensitive. Your output must conform exactly, such that when running the provided commands it will produce exactly the provided output (see below). In order to do this, newlines should be output as follows:
one newline before outputting "playing current:"
one newline before and one after outputting "playing reverse:"
one newline before and one after outputting "playing forward:"
one newline after each song name
#ifndef __DOUBLYLINKEDLIST_H__ #define __DOUBLYLINKEDLIST_H__ // // #include #include using namespace std;
class DoublyLinkedList { public: DoublyLinkedList(); ~DoublyLinkedList(); void append (const string& s); void insertBefore (const string& s); void insertAfter (const string& s); void remove (const string& s); bool empty(); void begin(); void end(); bool next(); bool prev(); bool find(const string& s); const std::string& getData() const;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started