Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help on a part of my Playlist Program. Step 9: Implement the Change position of song menu option in ExecuteMenu(). Prompt the user

I need help on a part of my Playlist Program.

Step 9: Implement the "Change position of song" menu option in ExecuteMenu().

Prompt the user for the current position of the song and the desired new position. Valid new positions are 1 - n (the number of nodes). If the user enters a new position that is less than 1, move the node to the position 1 (immediately after the head). If the user enters a new position greater than n, move the node to position n (the tail). 6 cases will be tested:

  • Moving the head node (1 pt)
  • Moving the tail node (1 pt)
  • Moving a node to the head (1 pt)
  • Moving a node to the tail (1 pt)
  • Moving a node up the list (1 pt)
  • Moving a node down the list (1 pt)

Ex:

CHANGE POSITION OF SONG Enter song's current position: 3 Enter new position for song: 2 "Canned Heat" moved to position 2

This is my .h file

#ifndef _PLAYLIST_H_ #define _PLAYLIST_H_ #include  using namespace std; class PlaylistNode{ public: PlaylistNode(); PlaylistNode(string, string, string, int); void InsertAfter(Playlist*); void SetNext(PlaylistNode*); string GetID() const; string GetSongName() const; string GetArtistName() const; int GetSongLength() const; PlaylistNode* GetNext() const; void PrintPlaylistNode() const; private: string uniqueID ; string songName ; string artistName; int songLength ; PlaylistNode* nextNodePtr ; }; class Playlist { public: Playlist(); void Playlist::push_back(PlaylistNode*) ; void AddSong(Playlist*); void RemoveSong(Playlist*); void ChangePosition(int, int); void OutputSongBYSpecificArtist(); void OutputTotalTime(); void OutputFullPlaylist(string); private: PlaylistNode* head; PlaylistNode* tail; }; #endif

This is my .cpp file

#include "PlaylistNode.h" PlaylistNode::PlaylistNode() { this->uniqueID = "none"; this->songName = "none"; this->artistName = "none"; this->songLength = 0; this->nextNodePtr = nullptr; } PlaylistNode::PlaylistNode(string initID, string tuneName, string singer, int length, PlaylistNode* nextLoc) { this->uniqueID = initID; this->songName = tuneName; this->artistName = singer; this->songLength = length; this->nextNodePtr = nextLoc; } void PlaylistNode::InsertAfter(PlaylistNode* newSong) { this->nextNodePtr = newSong; } void PlaylistNode::SetNext(PlaylistNode* nodePtr) { this->nextNodePtr = nodePtr; } string PlaylistNode::GetID() const { return uniqueID; } string PlaylistNode::GetSongName() const { return songName; } string PlaylistNode::GetArtistName() const { return artistName; } int PlaylistNode::GetSongLength() const { return songLength; } PlaylistNode* PlaylistNode::GetNext() { return nextNodePtr; } void PlaylistNode::PrintPlaylistNode() { /* Unique ID: S5543 Song Name: Angels Artist Name: Josh Groban Song Length (in seconds): 245 */ cout << "Unique ID: " << uniqueID << endl; cout << "Song Name: " << songName << endl; cout << "Artist Name: " << artistName << endl; cout << "Song Length (in seconds): " << songLength << endl; }

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

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions

Question

IDEA funds may not be spent on 2E learners. True False

Answered: 1 week ago