Question: 8 . 1 9 LAB: Playlist ( output linked list ) Given main ( ) , complete the SongNode class to include the function PrintSongInfo
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 userinput values.
Ex: If the input is:
Stomp!
The Brothers Johnson
The Dude
Quincy Jones
You Don't Own Me
Lesley Gore
the output is:
LIST OF SONGS
Title: Stomp!
Length:
Artist: The Brothers Johnson
Title: The Dude
Length:
Artist: Quincy Jones
Title: You Don't Own Me
Length:
Artist: Lesley Gore
main.cpp
#include
#include "SongNode.h
Function used to print the playlist
void PrintPlayListSongNode head
Store head into temp
SongNode temp head;
Set temp to next node
temptempGetNext;
Loop till the end of list
whiletempNULL
Print song info
tempPrintSongInfo;
If the current node is not the end node
iftempGetNext NULL
Print two newlines
cout endl endl;
Go to next node
temptempGetNext;
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 entered
getlinecin songTitle;
while songTitle
getlinecin songLength;
getlinecin songArtist;
currNode new SongNodesongTitle songLength, songArtist;
lastNodeInsertAftercurrNode;
lastNode currNode;
getlinecin songTitle;
Print linked list
cout "LIST OF SONGS" endl;
cout endl;
PrintPlayListheadNode;
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
SongNodestring songTitleInit, string songLengthInit string songArtistInit;
Parameterized constructor
SongNodestring songTitleInit, string songLengthInit string songArtistInit,SongNode nextLoc;
Function used to insert after node
void InsertAfterSongNode 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::SongNodestring songTitleInit, string songLengthInit, string songArtistInit
thissongTitle songTitleInit;
thissongLength songLengthInit;
thissongArtist songArtistInit;
thisnextNodeRef NULL;
Constructor
SongNode::SongNodestring songTitleInit, string songLengthInit, string songArtistInit, SongNode nextLoc
thissongTitle songTitleInit;
thissongLength songLengthInit;
thissongArtist songArtistInit;
thisnextNodeRef nextLoc;
Function used to insert after node
void SongNode::InsertAfterSongNode nodeLoc
SongNode tmpNext;
tmpNext thisnextNodeRef;
thisnextNodeRef nodeLoc;
nodeLocnextNodeRef tmpNext;
Function used to get the next node
SongNode SongNode::GetNext
return thisnextNodeRef;
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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
