Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C + + Given main ( ) , complete the SongNode class to include the function PrintSongInfo ( ) . Then write the PrintPlaylist

in C++ 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
Given main(), 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 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
*GIVEN CODE*
*main.cpp*
#include
#include "SongNode.h"
// TODO: Write PrintPlaylist() 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);
return 0;
}
*SongNode.h*Code
#include "iostream"
#include
using namespace std;
class SongNode {
private:
string songTitle;
string songLength;
string songArtist;
SongNode* nextNodeRef; // Reference to the next node
public:
SongNode(){
songTitle ="-1";
songLength ="";
songArtist ="";
nextNodeRef = nullptr;
}
// Constructor
SongNode(string songTitleInit, string songLengthInit, string songArtistInit);
// Constructor
SongNode(string songTitleInit, string songLengthInit, string songArtistInit, SongNode* nextLoc);
// insertAfter
void InsertAfter(SongNode* nodeLoc);
// Get location pointed by nextNodeRef
SongNode* GetNext();
// Prints song information
void PrintSongInfo();
};
*Songnode.cpp*Code
#include "SongNode.h"
// Constructor
SongNode::SongNode(string songTitleInit, string songLengthInit, string songArtistInit){
this->songTitle = songTitleInit;
this->songLength = songLengthInit;
this->songArtist = songArtistInit;
this->nextNodeRef = nullptr;
}
// 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
image text in transcribed

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

Automating Access Databases With Macros

Authors: Fish Davis

1st Edition

1797816349, 978-1797816340

More Books

Students also viewed these Databases questions

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago