Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer using the below driver code template You are to code some simple music player application making appropriate use of doubly linked lists with

Please answer using the below driver code template

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. a. Provide a Song class 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 places it 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. GIVEN THE C++ TEMPLATE

#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<

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

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

What is DDL?

Answered: 1 week ago