Question

In: Computer Science

C++ Linked Lists Don’t you love music? Everyone loves a great song playlist! Practice your understanding...

C++ Linked Lists

Don’t you love music? Everyone loves a great song playlist! Practice your

understanding of linked lists in C++ by creating list of songs / artist pairs.

Allow your user to add song / artist pairs to the list, remove songs (and

associated artist) from the list and be sure to also write a function to print

the list! Have fun!

Solutions

Expert Solution

`Hey,

Note: In case of any queries, just comment in box I would be very happy to assist all your queries

/*** Below is the complete code and sample output in the end ***/

#include<iostream>

using namespace std;

struct musicNode{

string songName;

string artistName;

musicNode *next;

};

class musicList{

private:

musicNode *head;

public:

musicList(){

head = NULL;

}

void addSong(string sName, string aName){

musicNode *ptr = new musicNode;

ptr->songName = sName;

ptr->artistName = aName;

ptr->next = NULL;

if(head == NULL){

head = ptr;

}

else{

musicNode *current = head;

while(current->next != NULL)

current = current->next;

current->next = ptr;

}

}

void deleteSong(string sName){

musicNode *temp = head;

musicNode *prev = NULL;

if(temp != NULL && temp->songName == sName){

head = head->next;

return;

}

while(temp != NULL && temp->songName != sName){

prev = temp;

temp = temp->next;

}

if(temp == NULL){

cout<<"Song Is not present in the list: "<<endl;

return ;

}

if(temp->next == NULL){

prev->next = NULL;

return ;

}

prev->next = temp->next;

//delete temp;

}

void printList(){

musicNode *current = head;

while(current != NULL){

cout<<current->songName<<":"<<current->artistName<<" -> ";

current = current->next;

}

cout<<endl;

}

};

void displayMenu(){

cout<<"1. Add Song"<<endl;

cout<<"2. Delete Song"<<endl;

cout<<"3. Print music List"<<endl;

cout<<"4. Exit"<<endl;

}

int main(){

musicList mList;

while(true){

displayMenu();

cout<<"Enter your choice"<<endl;

int option;

cin>>option;

cin.ignore(26, '\n');

if(option == 1){

string songName;

string artistName;

cout<<"Enter the song Name"<<endl;

getline(cin,songName);

cout<<"Enter the artist Name"<<endl;

getline(cin,artistName);

mList.addSong(songName, artistName);

}

if(option ==2){

string songName;

cout<<"enter the songName to delete"<<endl;

getline(cin, songName);

mList.deleteSong(songName);

}

if(option ==3){

mList.printList();

}

if(option ==4){

cout<<"Exiting"<<endl;

break;

}

}

}

/*** Output ***/

Kindly revert for any queries

Thanks.


Related Solutions

C++ Linked Lists Don’t you love music? Everyone loves a great song playlist! Practice your understanding...
C++ Linked Lists Don’t you love music? Everyone loves a great song playlist! Practice your understanding of linked lists in C++ by creating list of songs / artist pairs. Allow your user to add song / artist pairs to the list, remove songs (and associated artist) from the list and be sure to also write a function to print the list! Have fun! Using Vector or Pointer but please write a new code don't copy the one that exist before
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of...
C++ Linked Lists Practice your understanding of linked lists in C++ by creating a list of songs/artist pairs. Allow your user to add song / artist pairs to the list, remove songs (and associated artist) from the list and be sure to also write a function to print the list! Have fun! Make sure you show your implementation of the use of vectors in this lab (You can use them too ) You MUST modularize your code ( meaning, there...
(C++) All programs will be included! This lab gives you a little practice with linked lists...
(C++) All programs will be included! This lab gives you a little practice with linked lists ·Debug insertSorted() and implement sorted() in numberlist.cpp ·Hint: insertSorted() is just missing a few parts. What is in the function can work fine once you add the right code, though you are free to rewrite it ·You need to have main.cpp, numberlist.h and numberlist.cpp in this project, and if you are using Code::Blocks, remember to set the Build Options to indicate you want to...
C++ language or Python. Linked Lists You are given a linked list that contains N integers....
C++ language or Python. Linked Lists You are given a linked list that contains N integers. You are to perform the following reverse operation on the list: Select all the subparts of the list that contain only even integers. For example, if the list is {1,2,8,9,12,16}, then the selected subparts will be {2,8}, {12,16}. Reverse the selected subpart such as {8,2} and {16,12}. The list should now be {1,8,2,9,16,12}. Your node definition should consist of 2 elements: the integer value...
In order to practice on Linked Lists, you will implement one from scratch which will allow...
In order to practice on Linked Lists, you will implement one from scratch which will allow you to examine how they work and explore their capabilities and limitations. You will build a doubly-circular linked list. In doubly linked lists, each node in the list has a pointer to the next node and the previous node. In circular linked lists, the tail node’s next pointer refers to the head and the head node’s previous pointer refers to the tail rather than...
Using C++, you will create a program, where you will create two doubly linked lists. These...
Using C++, you will create a program, where you will create two doubly linked lists. These doubly linked lists will contain integers within them. Using the numbers in both of these linked lists, you add the numbers together, and insert the addition of the two numbers into a singly linked list. the input can be from the user or you just write the input. for example, if one number in the doubly linked list is 817 and in the other...
Please edit the code with linked lists in C++ Please provide your BookData.txt file as well...
Please edit the code with linked lists in C++ Please provide your BookData.txt file as well BookRecord.cpp file #include "BookRecord.h" #include <stdio.h> #include <string.h> #include <iostream> #include <fstream> using namespace std; BookRecord::BookRecord() {    strcpy_s(m_sName, "");    m_lStockNum = 0;    m_iClassification = 0;    m_dCost = 0.0;    m_iCount = 0; } BookRecord::BookRecord(const char* name, long sn, int cl, double cost) {    strcpy_s(m_sName, name);    m_lStockNum = sn;    m_iClassification = cl;    m_dCost = cost;    m_iCount...
Working with Linked Lists in C++ Tasks As stated in the objectives, you have two methods...
Working with Linked Lists in C++ Tasks As stated in the objectives, you have two methods to implement. These methods (which contain TODO comments) are found in linked_list.cpp. Part 1 Implement the copy constructor; use the LinkedBag as inspiration for your solution as the technique of creating a deep copy is essentially the same. Part 2 Implement the replace method. //linked_list.cpp #include "linked_list.h" // Header file #include <cassert> template<class Object> LinkedList<Object>::LinkedList() : headPtr( nullptr ), itemCount( 0 ) { }...
Can you write a program for snakes and ladder board game using linked lists in c++
Can you write a program for snakes and ladder board game using linked lists in c++
Can you program Exploding kittens card game in c++ using linked lists and classes! The game...
Can you program Exploding kittens card game in c++ using linked lists and classes! The game is played with between 2 and 4 players. You'll have a deck of cards containing some Exploding Kittens. You play the game by putting the deck face down and taking turns drawing cards until someone draws an Exploding Kitten. When that happens, that person explodes. They are now dead and out of the game. This process continues until there's only one player left, who...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT