Question: You are to code some simple music player application making appropriate use of doubly linked lists, as described hereafter. Create a doubly linked list for

You are to code some simple music player application making appropriate use of doubly linked lists, as described hereafter. Create a doubly linked list for a music playlist. a. Provide a class Song that has a title and a singer as data members. b. Create a doubly linked list, with a head node (musicPlaylist) pointing to the first song on the list. c. Display a menu for the user to choose an option, as follows: 1. Add a song 2. Delete a song 3. Play a song 4. Skip forward 5. Skip backward 6. Exit Adding and deleting songs (#1-2) should update the playlist accordingly. Adding a song takes place at the end of the list. Playing a song (#3) will prompt the user to enter the title of the song and print both the title and singer (e.g., Now playing by ) 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 Ex3Driver.cpp file to continue.

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------cpp file:

#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() << " Artist: " << s.getSinger() << endl<

return out;

}

bool operator==(const Song &rhs) {

if ((rhs.title == title) && (rhs.singer == singer))

return true;

else

return false;

}

string getTitle() const { return title; }

string getSinger() const { return singer; }

void setTitle(string t) { title = t; }

void setSinger(string s) { singer = s; }

Song &operator=(const Song &s) {

title = s.title;

singer = s.singer;

return *this;

}

private:

string title;

string singer;

};

//Doubly Linked List structure

template <typename Object>

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 } { }

};

//function to create Doubly Linked List with values

template <typename Object>

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 <typename Object>

void printDLL(DoubleNode* head)

{

while (head != nullptr)

{

cout << head->data;

head = head->next;

}

cout << endl;

}

void menu() {

cout <<"1. Add a Song "

<<"2. Delete a Song "

<<"3. Play a Song "

<<"4. Forward "

<<"5. Backward "

<<"6. Show Playlist "

<<"7.Exit "

<<"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;

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

//your code goes here

break;

case 5: //backward

//your code goes here

break;

case 6: //Display Playlist

printDLL(head);

break;

case 7: //exit

cout << "Exiting playlist... ";

break;

}

} while (option != 7);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!