Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(C++)You will be building a linked list. Make sure to keep track of both the hea

ID: 3811392 • Letter: #

Question

(C++)You will be building a linked list. Make sure to keep track of both the head and tail nodes.

(1) Create three files to submit.

•Playlist.h - Class declaration

•Playlist.cpp - Class definition

•main.cpp - main() function

Build the PlaylistNode class per the following specifications. Note: Some functions can initially be function stubs (empty functions), to be completed in later steps.

-Default constructor (1 pt)

-Parameterized constructor (1 pt)

Public member functions

-InsertAfter() (1 pt)

-SetNext() - Mutator (1 pt)

-GetID() - Accessor

-GetSongName() - Accessor

-GetArtistName() - Accessor

-GetSongLength() - Accessor

-GetNext() - Accessor

-PrintPlaylistNode()

Private data members

-string uniqueID - Initialized to "none" in default constructor

-string songName - Initialized to "none" in default constructor

-string artistName - Initialized to "none" in default constructor

-int songLength - Initialized to 0 in default constructor

-PlaylistNode* nextNodePtr - Initialized to 0 in default constructor

Ex. of PrintPlaylistNode output:

(2) In main(), prompt the user for the title of the playlist. (1 pt)

Ex:


(3) Implement the PrintMenu() function. PrintMenu() takes the playlist title as a parameter and outputs a menu of options to manipulate the playlist. Each option is represented by a single character. Build and output the menu within the function.

If an invalid character is entered, continue to prompt for a valid choice. Hint: Implement Quit before implementing other options. Call PrintMenu() in the main() function. Continue to execute the menu until the user enters q to Quit. (3 pts)

Ex:


(4) Implement "Output full playlist" menu option. If the list is empty, output: Playlist is empty (3 pts)

Ex:


(5) Implement the "Add song" menu item. New additions are added to the end of the list. (2 pts)

Ex:


(6) Implement the "Remove song" function. Prompt the user for the unique ID of the song to be removed.(4 pts)

Ex:


(7) Implement the "Change position of song" menu option. 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 (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:


(8) Implement the "Output songs by specific artist" menu option. Prompt the user for the artist's name, and output the node's information, starting with the node's current position. (2 pt)

Ex:


(9) Implement the "Output total time of playlist" menu option. Output the sum of the time of the playlist's songs (in seconds). (2 pts)

Ex:

Explanation / Answer

Here is the code for PlayList.h:

#pragma once
#include <iostream>
#include <string>
#include <string>
#include <vector>
#include <list>
using namespace std;

class Playlist
{
private:
string uniqueID;
string songName;
string artistName;
int songLength;

public:
Playlist() { uniqueID = "", songName = "", artistName = "", songLength = 0; };
Playlist(string auniqueId, string asongName, string aArtistName, int aSongLength);
void InsertAfter();
void SetNext();
string GetID();
string GetSongName();
string GetArtistName();
int GetSongLength();
string GetNext();
void PrintPlaylistNode();
};
//#pragma once
//#include "Playlist.h"
//#include <list>
class PlaylistNode
{
private:
std::list<Playlist> library;
Playlist get(list<Playlist> _list, int _i);
void PrintPlaylist(Playlist aPlayList);
public:
void Addsong(Playlist aPlayslist);
void Removesong(string aUnwiid);
void Changeposition(int oldPostion, int anewPostion);
void PrintSongByartist(string aAstist);
void PrintSongtotalLen();
void PrintFullPlayList();
};

Here is the code for PlayList.cpp:

#include "Playlist.h"
Playlist::Playlist(string auniqueId, string asongName, string aArtistName, int aSongLength)
{
uniqueID = auniqueId;
songName = asongName;
artistName = aArtistName;
songLength = aSongLength;
}
string Playlist::GetArtistName()
{
return artistName;
}
string Playlist::GetID()
{
return uniqueID;
}
string Playlist::GetSongName()
{
return songName;
}

int Playlist::GetSongLength()
{
return songLength;
}

void Playlist::SetNext()
{

}
string Playlist::GetNext()
{
return "";
}
void Playlist::InsertAfter() {
}

void Playlist::PrintPlaylistNode()
{
cout << "Unique ID:" << uniqueID << endl;
cout << "Song Name:" << songName << endl;
cout << "Artist Name:" << artistName << endl;
cout << "Song Length (in seconds):" << songLength << endl;
}
////
void PlaylistNode::Addsong(Playlist aPlaylist)
{
library.push_back(aPlaylist);
}
void PlaylistNode::Removesong(string aUnwiid)
{
if (library.size() > 0)
{
for (list<Playlist>::iterator it = library.begin(); it != library.end(); ++it)
{
if (it->GetID() == aUnwiid)
{
cout << it->GetSongName() << endl;
//library.remove(*it);
break;
}
}
}
}
Playlist PlaylistNode::get(list<Playlist> _list, int _i) {
list<Playlist>::iterator it = _list.begin();
for (int i = 0; i<_i; i++) {
++it;
}
return *it;
}
std::list<Playlist>::iterator it;
void PlaylistNode::PrintFullPlayList()
{
for (it = library.begin(); it != library.end(); ++it)
{
PrintPlaylist(*it);
}

}
void PlaylistNode::PrintSongByartist(string aartiename)
{
for (it = library.begin(); it != library.end(); ++it)
{
if (it->GetArtistName() == aartiename)
PrintPlaylist(*it);
}
}
void PlaylistNode::PrintSongtotalLen()
{
int TotalSonglengst = 0;
for (it = library.begin(); it != library.end(); ++it)
{
TotalSonglengst += it->GetSongLength();
}
cout << "Total songs Length (in seconds):" << TotalSonglengst << endl;
}
void PlaylistNode::PrintPlaylist(Playlist aPlayList)
{
cout << "Unique ID:" << aPlayList.GetID() << endl;
cout << "Song Name:" << aPlayList.GetSongName() << endl;
cout << "Artist Name:" << aPlayList.GetArtistName() << endl;
cout << "Song Length (in seconds):" << aPlayList.GetSongLength() << endl;
}
void PlaylistNode::Changeposition(int oldPostion, int newPostinon)
{
if (!library.empty())
{
if (newPostinon <= library.size())
{
Playlist oldPlalist = get(library, oldPostion);
Playlist New_Playlist = get(library, newPostinon);
Playlist pldpay(oldPlalist.GetID(), oldPlalist.GetSongName(), oldPlalist.GetArtistName(), oldPlalist.GetSongLength());
/*library.insert(pldpay,newPostinon);
library.insert(New_Playlist, oldPostion);*/
}
else
{
cout << "The Postion is Not in the Range of LIB" << endl;
}
}
}

And the tester is:

#include <iostream>
#include "Playlist.cpp"
using namespace std;
int main()
{
char choice;
string uqid = "";
string songnam = "";
string artname, temp;
int len;
PlaylistNode PlaylistNode;
do
{
cout << "MENU" << endl;
cout << "a - Add song: " << endl;
cout << "d - Remove song: " << endl;
cout << "c - Change position of song " << endl;
cout << "s - Output songs by specific artist: " << endl;
cout << "t - Output total time of playlist (in seconds): " << endl;
cout << "o - Output full playlist " << endl;
cout << "q - QUIT PROGRAM " << endl;
cout << "Please enter your selection." << endl;
cin >> choice;

switch (choice)
{
case 'a':
{
cout << "ADD SONG" << endl;
cout << "Enter song's unique ID:" << endl;
getline(cin, temp);
getline(cin, uqid);
cout << "Enter song's name:" << endl;
getline(cin, songnam);
cout << "Enter artist's name:" << endl;
getline(cin, artname);
cout << "Enter Song len" << endl;
cin >> len;
Playlist playlistobj(uqid, songnam, artname, len);
PlaylistNode.Addsong(playlistobj);
break; //Add record
}
case 'd':
{
cout << "REMOVE SONG" << endl;
cout << "Enter song's unique ID:" << endl;
cin >> uqid;
PlaylistNode.Removesong(uqid);
}
break; //Display record
case 'c':
{
int Creentpos = 0;
int newpos = 0;
cout << "Enter song's current position:" << endl;
cin >> Creentpos;
cout << "Enter new position for song:" << endl;
cin >> newpos;
PlaylistNode.Changeposition(Creentpos, newpos);
}
case 's':
cout << "Enter artist's name:" << endl;
cin >> artname;
PlaylistNode.PrintSongByartist(artname);
break; //EDit record
case 't':
PlaylistNode.PrintSongtotalLen();
break; //EDit record

case 'o':
PlaylistNode.PrintFullPlayList();
break; //EDit record
case 'q':
cout << "QUIT PROGTRAM--" << endl;
break;
default: cout << "Invalid Selection" << endl;
}
} while(choice != 'q');
//system("PAUSE");
return 0;
}