Exercise 3:
You are to code some simple music player application making appropriate use of doubly linked
lists with head and tail, as described hereafter.
Create a doubly linked list for a music playlist.
Adding and deleting songs (#1-2) should update the playlist accordingly. Adding a song places it
at the end of the list.
Playing a song (#3) will prompt the user to enter the title of the song and will set the currentSong
pointer to that location in the playlist before printing both the title and singer (e.g., Now playing
by ) . Use the eraseInDLL function definition to implement delete.
Skipping forward or backward (#4-5) will jump to the previous song or the next song,
respectively, and display its title and singer (as per above). Skip forward on the last song takes
you to the beginning of the list. Skip backward on the first song takes you to the last song of the
list.
Exit will quit the program.
*You may use provided main function in Ex3.cpp file to continue.
Sample Output:
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 1
Enter song title: Trouble
Enter singer: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 6
Printing playlist...
Title: Staying Alive
Artist: Bee Gees
Title: Hotel California
Artist: The Eagles
Title: Saturnalia
Artist: Marilyn Manson
Title: Potions
Artist: Puscifer
Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 3
Enter the title of the song to play: Trouble
Enter singer: Taylor Swift
Now playing...
Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 4
Now Playing...
Title: Staying Alive
Artist: Bee Gees
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 5
Now Playing...
Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 1
Enter song title: Lavender Haze
Enter singer: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 4
Now Playing...
Title: Lavender Haze
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 6
Printing playlist...
Title: Staying Alive
Artist: Bee Gees
Title: Hotel California
Artist: The Eagles
Title: Saturnalia
Artist: Marilyn Manson
Title: Potions
Artist: Puscifer
Title: Trouble
Artist: Taylor Swift
Title: Lavender Haze
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 2
Enter the title of the song to delete: Lavender Haze
Enter singer: Taylor Swift
Deleted!
1. Add a Song
2. Delete a Song
3. Pl.
Exercise 3 You are to code some simple music player application .pdf
1. Exercise 3:
You are to code some simple music player application making appropriate use of doubly linked
lists with head and tail, as described hereafter.
Create a doubly linked list for a music playlist.
Adding and deleting songs (#1-2) should update the playlist accordingly. Adding a song places it
at the end of the list.
Playing a song (#3) will prompt the user to enter the title of the song and will set the currentSong
pointer to that location in the playlist before printing both the title and singer (e.g., Now playing
by ) . Use the eraseInDLL function definition to implement delete.
Skipping forward or backward (#4-5) will jump to the previous song or the next song,
respectively, and display its title and singer (as per above). Skip forward on the last song takes
you to the beginning of the list. Skip backward on the first song takes you to the last song of the
list.
Exit will quit the program.
*You may use provided main function in Ex3.cpp file to continue.
Sample Output:
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 1
Enter song title: Trouble
Enter singer: Taylor Swift
1. Add a Song
2. Delete a Song
2. 3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 6
Printing playlist...
Title: Staying Alive
Artist: Bee Gees
Title: Hotel California
Artist: The Eagles
Title: Saturnalia
Artist: Marilyn Manson
Title: Potions
Artist: Puscifer
Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 3
Enter the title of the song to play: Trouble
Enter singer: Taylor Swift
Now playing...
3. Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 4
Now Playing...
Title: Staying Alive
Artist: Bee Gees
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 5
Now Playing...
Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
4. 5. Backward
6. Show Playlist
7.Exit
Choose an option: 1
Enter song title: Lavender Haze
Enter singer: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 4
Now Playing...
Title: Lavender Haze
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 6
Printing playlist...
Title: Staying Alive
Artist: Bee Gees
Title: Hotel California
5. Artist: The Eagles
Title: Saturnalia
Artist: Marilyn Manson
Title: Potions
Artist: Puscifer
Title: Trouble
Artist: Taylor Swift
Title: Lavender Haze
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 2
Enter the title of the song to delete: Lavender Haze
Enter singer: Taylor Swift
Deleted!
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 6
6. Printing playlist...
Title: Staying Alive
Artist: Bee Gees
Title: Hotel California
Artist: The Eagles
Title: Saturnalia
Artist: Marilyn Manson
Title: Potions
Artist: Puscifer
Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 5
Now Playing...
Title: Trouble
Artist: Taylor Swift
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
7. 6. Show Playlist
7.Exit
Choose an option: 4
Now Playing...
Title: Staying Alive
Artist: Bee Gees
1. Add a Song
2. Delete a Song
3. Play a Song
4. Forward
5. Backward
6. Show Playlist
7.Exit
Choose an option: 7
Exiting playlist...
#include
#include
using namespace std;
class Song {
public:
Song(string t = "", string s = "") : title{ t }, singer{ s }{ }
friend ostream &operator<<(ostream &out, const Song & s) {
out << "Title: " << s.getTitle() << "nArtist: " << s.getSinger() << endl<
struct DoubleNode
{
Object data;
DoubleNode *prev;
DoubleNode *next;
DoubleNode(const Object & d = Object{}, DoubleNode * p = nullptr, DoubleNode * n =
nullptr)
: data{ d }, prev{ p }, next{ n } { }
8. };
//function to create Doubly Linked List with values
template
void createDoublyLinkedList(Object ary[], int size,DoubleNode*& head,DoubleNode*& tail)
{
head = new DoubleNode(ary[0]);
DoubleNode* temp = head;
for (int i = 1; i < size; i++)
{
DoubleNode* node = new DoubleNode(ary[i]);
temp->next = node;
node->prev = temp;
temp = node;
}
tail = temp;
}
template
void printDLL(DoubleNode* head)
{
while (head != nullptr)
{
cout << head->data;
head = head->next;
}
cout << endl;
}
template
bool eraseInDLL(DoubleNode*& head, DoubleNode*& tail, Object givenValue) {
DoubleNode *temp = head;
// your code
}
void menu() {
cout <<"1. Add a Songn"
9. <<"2. Delete a Songn"
<<"3. Play a Songn"
<<"4. Forwardn"
<<"5. Backwardn"
<<"6. Show Playlistn"
<<"7.Exitn"
<<"Choose an option: ";
}
int main()
{
string title;
string singer;
bool success;
Song MusicList[10];
Song a("Staying Alive", "Bee Gees");
MusicList[0] = a;
Song b("Hotel California", "The Eagles");
MusicList[1] = b;
Song c("Saturnalia", "Marilyn Manson");
MusicList[2] = c;
Song d("Potions", "Puscifer");
MusicList[3] = d;
DoubleNode* head;
DoubleNode * tail;
createDoublyLinkedList(MusicList, 4,head,tail);
DoubleNode *currentSong =head;
Song song;
bool found = false;
int option;
do {
menu();
cin >> option;
cout << endl;
10. cin.ignore();
cin.clear();
switch (option) {
case 1: // Add a Song
{
cout << "Enter song title: ";
getline(cin, title);
cout << "Enter singer: ";
getline(cin, singer);
DoubleNode *newSong = new DoubleNode(Song(title,singer));
//your code goes here
}
break;
case 2: // Delete a Song
cout << "Enter the title of the song to delete: ";
getline(cin, title);
cout << "Enter singer: ";
getline(cin, singer);
//your code goes here
break;
case 3: // Paly a Song
found = false;
cout << "Enter the title of the song to play: ";
getline(cin, title);
cout << "Enter singer: ";
getline(cin, singer);
song.setTitle(title);
song.setSinger(singer);
//your code goes here
break;
case 4: //forward
11. //your code goes here
break;
case 5: //backward
//your code goes here
break;
case 6: //print all
//your code goes here
break;
case 7: //Exit
cout << "Exiting playlist...nn";
break;
}
} while (option != 7);
return 0;
}