Question: 8 . 1 9 LAB: Playlist ( output linked list ) Given main ( ) , complete the SongNode class to include the function PrintSongInfo

8.19 LAB: Playlist (output linked list)
Given main(), complete the SongNode class to include the function PrintSongInfo(). Then write the PrintPlaylist() function in main.cpp to print all songs in the playlist. DO NOT print the head node, which does not contain user-input values.
Ex: If the input is:
Stomp!
380
The Brothers Johnson
The Dude
337
Quincy Jones
You Don't Own Me
151
Lesley Gore
-1
the 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
-----------------------------------------main.cpp
#include
#include "SongNode.h"
// Function used to print the playlist
void PrintPlayList(SongNode* head)
{
// Store head into temp
SongNode *temp = head;
// Set temp to next node
temp=temp->GetNext();
// Loop till the end of list
while(temp!=NULL)
{
// Print song info
temp->PrintSongInfo();
// If the current node is not the end node
if(temp->GetNext()!= NULL)
// Print two newlines
cout << endl << endl;
// Go to next node
temp=temp->GetNext();
}
}
// Main function
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;
getline(cin, songTitle);
}
// Print linked list
cout << "LIST OF SONGS" << endl;
cout <<"-------------"<< endl;
PrintPlayList(headNode);
cout << endl;
}
-------------------------------------------------------
songNode.h
#include
#include
using namespace std;
// Create a SongNode class
class SongNode
{
private:
// Private data members
string songTitle;
string songLength;
string songArtist;
SongNode* nextNodeRef;
public:
// Default constructor
SongNode()
{
songTitle ="";
songLength ="";
songArtist ="";
nextNodeRef = NULL;
}
// Parameterized constructor
SongNode(string songTitleInit, string songLengthInit ,string songArtistInit);
// Parameterized constructor
SongNode(string songTitleInit, string songLengthInit ,string songArtistInit,SongNode* nextLoc);
// Function used to insert after node
void InsertAfter(SongNode* nodeLoc);
// Function used to get the next node
SongNode* GetNext();
// Function used to print the song information
void PrintSongInfo();
};
------------------------------------------
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;
}
// Function used to insert after node
void SongNode::InsertAfter(SongNode* nodeLoc)
{
SongNode* tmpNext;
tmpNext = this->nextNodeRef;
this->nextNodeRef = nodeLoc;
nodeLoc->nextNodeRef = tmpNext;
}
// Function used to get the next node
SongNode* SongNode::GetNext()
{
return this->nextNodeRef;
}
// Function used to print the song information
void SongNode::PrintSongInfo()
{
cout<<"Title: "<

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 Programming Questions!