4. SongNode* tmpNext;
tmpNext = this->nextNodeRef;
this->nextNodeRef = nodeLoc;
nodeLoc->nextNodeRef = tmpNext;
}
// Get location pointed by nextNodeRef
SongNode* SongNode::GetNext() {
return this->nextNodeRef;
}
// Prints song information
void SongNode::PrintSongInfo() {
cout << "Title: " << this->songTitle << endl;
cout << "Length: " << this->songLength << endl;
cout << "Artist: " << this->songArtist << endl << endl;
}
// main.cpp
// Write PrintPlaylist() function
void PrintPlaylist(SongNode *song) {
song = song->GetNext(); // skip the dummy head node
while (song != NULL) {
song->PrintSongInfo();
song = song->GetNext();
}
}
int main() {
SongNode* headNode;
SongNode* currNode;
SongNode* lastNode;
string songTitle;
string songLength;
string songArtist;
// Front of nodes list
headNode = new SongNode();
lastNode = headNode;
// Read user input until -1 entered
getline(cin, songTitle);
while (songTitle != "-1") {
getline(cin, songLength);
getline(cin, songArtist);
currNode = new SongNode(songTitle, songLength, songArtist);
lastNode->InsertAfter(currNode);
lastNode = currNode;
5. getline(cin, songTitle);
}
// Print linked list
cout << "nLIST OF SONGS" << endl;
cout << "-------------" << endl;
PrintPlaylist(headNode);
return 0;
}
SongNode.cpp:
#include "SongNode.h"
// Constructor
SongNode::SongNode(string songTitleInit, string songLengthInit, string songArtistInit) {
this->songTitle = songTitleInit;
this->songLength = songLengthInit;
this->songArtist = songArtistInit;
this->nextNodeRef = NULL;
}
// Constructor
SongNode::SongNode(string songTitleInit, string songLengthInit, string songArtistInit, SongNode*
nextLoc) {
this->songTitle = songTitleInit;
this->songLength = songLengthInit;
this->songArtist = songArtistInit;
this->nextNodeRef = nextLoc;
}
// insertAfter
void SongNode::InsertAfter(SongNode* nodeLoc) {
SongNode* tmpNext;
tmpNext = this->nextNodeRef;
this->nextNodeRef = nodeLoc;
nodeLoc->nextNodeRef = tmpNext;
}
// Get location pointed by nextNodeRef
SongNode* SongNode::GetNext() {
return this->nextNodeRef;
}
// TODO: Write PrintSongInfo() function
please solve it in c++ thank you!
Given main(0, complete the SongNode class to include the function PrintSonglnfo(). Then write
the PrintPlaylist() function in main.cpp to print all songs in the playlist. DO NOT print the dummy
head node. Ex: If the input is: Stomp! 380 The Brothers Johnson The Dude 337 Quincy Jones You
6. Don't own Me 151 Lesley Gore -1the output is: LIST OF SONGS Title: Stomp! Length: 380 Artist:
The Brothers Johnson Title: The Dude Length: 337 Artist: Quincy Jones Title: You Don't Own Me
Length: 151 Artist: Lesley Gore