Question: Pls Help The yellow highlight is a part i need to fix! Main.cpp #include #include #include PlaylistNode.h using namespace std; // function declaration char PrintMenu(string
Pls Help The yellow highlight is a part i need to fix!
Main.cpp
#include
// function declaration char PrintMenu(string playlistTitle); void AddSong(PlaylistNode*& head, PlaylistNode*& tail); void RemoveSong(PlaylistNode*& head, PlaylistNode*& tail); void MoveSong(PlaylistNode*& head, PlaylistNode*& tail); void SpecificArtistSong(PlaylistNode* head, PlaylistNode* tail);
int main() { string playlistTitle; PlaylistNode *head = NULL, *tail = NULL; char choice;
// input the name of play list cout
// loop that continues until the user exits do { choice = PrintMenu(playlistTitle); if(choice == 'a') { AddSong(head, tail); } else if(choice == 'd') { RemoveSong(head, tail); } else if(choice == 'c') { MoveSong(head, tail); } else if(choice == 's') { SpecificArtistSong(head, tail); } else if(choice == 't') { cout
// loop over the list to calculate the total time of all songs while(curr != NULL) { total_time += curr->GetSongLength(); curr = curr->GetNext(); } cout
// loop over the list, displaying each song while(curr != NULL) { coutPrintPlaylistNode(); coutGetNext(); pos++; } } } cout
return 0; }
// function to display the menu, input the user choice and return it char PrintMenu(string playlistTitle) { char option; cout>option; option = tolower(option);
// loop that continues until user enters a valid option while(option != 'a' && option != 'd' && option != 'c' && option != 's' && option != 't' && option != 'o' && option != 'q') { cout>option; option = tolower(option); }
return option; }
// function to add a song at the end of the list void AddSong(PlaylistNode*& head, PlaylistNode*& tail) { string uniqueID; string songName ; string artistName; int songLength; cout
// input song details cout>uniqueID; cout>songLength;
if(head == NULL) // empty list, create a new head node and set tail node to head { head = new PlaylistNode(uniqueID, songName, artistName, songLength);; tail = head; } else{ // insert the song after tail tail->InsertAfter(uniqueID, songName, artistName, songLength); tail = tail->GetNext(); // update tail to the new node created } }
// function to remove a song from the list void RemoveSong(PlaylistNode*& head, PlaylistNode*& tail) { string uniqueID; cout
// input song ID cout>uniqueID;
if(head != NULL) // non-empty list { PlaylistNode *curr = head; PlaylistNode *prev = NULL;
// loop to get and remove the node with ID while(curr != NULL) { if(curr->GetID() == uniqueID) // song found { if(prev == NULL){ // remove head node head = head->GetNext(); if(head == NULL) // empty list after removal tail = NULL; } else{ prev->SetNext(curr->GetNext()); if(prev->GetNext() == NULL) // last node removed, update tail to prev tail = prev; }
coutGetSongName()
// remove current node curr->SetNext(NULL); delete curr; curr = NULL; return; }
prev = curr; curr = curr->GetNext(); } }
cout
// function to change the position of a song void MoveSong(PlaylistNode*& head, PlaylistNode*& tail) { cout
// input the current and new position cout>curr_pos; cout>new_pos;
int n = 0; PlaylistNode *curr = head; // loop to calculate the number of songs in the list while(curr != NULL) { n++; curr = curr->GetNext(); }
// validate current position if(curr_pos > 0 && curr_pos
// update new_pos to valid position if(new_pos n) new_pos = n;
if(curr_pos != new_pos) // curr_pos and new_pos are not same { PlaylistNode* current; curr = head; PlaylistNode* prev = NULL;
int pos = 0;
// get the node to change while(curr != NULL) { pos++; if(pos == curr_pos) { // remove the current node from current position current = curr; if(prev == NULL){ head = curr->GetNext(); if(head->GetNext() == NULL) tail = head; } else{ prev->SetNext(curr->GetNext()); if(prev->GetNext() == NULL) tail = prev; } break; }
prev = curr; curr = curr->GetNext(); }
current->SetNext(NULL);
// get the node where to insert curr = head; prev = NULL;
pos = 1; while((curr != NULL) && (pos != new_pos)) { prev = curr; curr = curr->GetNext(); pos++; }
// insert the node in new position current->SetNext(curr); if(prev == NULL) { head = current; }else if(prev->GetNext() == NULL) { tail->SetNext(current); tail = current; }else prev->SetNext(current);
coutGetSongName()
// function to display the songs from a given artist void SpecificArtistSong(PlaylistNode* head, PlaylistNode* tail) { string artistName; cout
// input artist name cout
PlaylistNode *curr = head; int pos = 1;
// loop over the list, displaying the songs by the given artist while(curr != NULL) { if(curr->GetArtistName() == artistName){ coutPrintPlaylistNode(); coutGetNext(); pos++; } }
************************************************************************
PlaylistNode.cpp :
#include "PlaylistNode.h" #include
// default constructor PlaylistNode::PlaylistNode() : uniqueID("none"), songName("none"), artistName("none"), songLength(0), nextNodePtr(0) {}
// Parameterized constructor PlaylistNode::PlaylistNode(string ID, string sname, string aname, int len) : uniqueID(ID), songName(sname), artistName(aname), songLength(len), nextNodePtr(0) {}
// function to insert the given song after this node void PlaylistNode:: InsertAfter(string ID,string sname,string aname,int len) { // create a new node to store the input song details PlaylistNode* node = new PlaylistNode(ID,sname,aname,len); node->SetNext(this->nextNodePtr); // update node's next to next of this song this->nextNodePtr = node; // update next of this song to node }
// updates the nextNodePtr pointer of this node to next void PlaylistNode:: SetNext(PlaylistNode *node) { nextNodePtr = node; }
// returns the songID string PlaylistNode:: GetID() { return uniqueID; }
// return the song name string PlaylistNode:: GetSongName() { return songName; }
// return the artist name string PlaylistNode:: GetArtistName() { return artistName; }
// return the song length int PlaylistNode:: GetSongLength() { return songLength; }
// return the nextNodePtr PlaylistNode* PlaylistNode:: GetNext() { return nextNodePtr; }
// function to display the song details void PlaylistNode::PrintPlaylistNode() { cout
*-*********************************************************************************
PlaylistNode.h
#ifndef PLAYLISTNODE_H #define PLAYLISTNODE_H
#include
class PlaylistNode { private: string uniqueID; // unique ID of the song string songName ; // name of the song string artistName; // artist of the song int songLength; // length of song in seconds PlaylistNode* nextNodePtr; // pointer to next song in the list
public: PlaylistNode(); PlaylistNode(string ID, string sname, string aname, int len); void InsertAfter(string ID,string sname,string aname,int len); void SetNext(PlaylistNode *node); string GetID(); string GetSongName(); string GetArtistName(); int GetSongLength(); PlaylistNode* GetNext(); void PrintPlaylistNode();
};
#endif
*****************************************************************************
The Problem:





Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
