You will be building a linked list Make sure to keep track o

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 (use file provided)
•   Playlist.cpp - Class definition
•   main.cpp - main() function


Build the PlaylistNode class per the following specifications.

•   Default constructor

•   Parameterized constructor

•   Public member functions
o   InsertAfter()
o   SetNext() - Mutator
o   GetID() - Accessor
o   GetSongName() - Accessor
o   GetArtistName() - Accessor
o   GetSongLength() - Accessor
o   GetNext() - Accessor
o   PrintPlaylistNode()

•   Private data members
o   string uniqueID - Initialized to \"none\" in default constructor
o   string songName - Initialized to \"none\" in default constructor
o   string artistName - Initialized to \"none\" in default constructor
o   int songLength - Initialized to 0 in default constructor
o   PlaylistNode* nextNodePtr - Initialized to 0 in default constructor

Note: Some functions can initially be function stubs (empty functions), to be completed in later steps.


Ex. of PrintPlaylistNode output:

Unique ID: S123
Song Name: Peg
Artist Name: Steely Dan
Song Length (in seconds): 237

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

Ex:
Enter playlist\'s title: JAMZ

(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.


Ex:
JAMZ PLAYLIST MENU
a - Add song
d - Remove song
c - Change position of song
s - Output songs by specific artist
t - Output total time of playlist (in seconds)
o - Output full playlist
q - Quit

Choose an option:

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


Ex:
JAMZ - OUTPUT FULL PLAYLIST
1.
Unique ID: SD123
Song Name: Peg
Artist Name: Steely Dan
Song Length (in seconds): 237

2.
Unique ID: JJ234
Song Name: All For You
Artist Name: Janet Jackson
Song Length (in seconds): 391

3.
Unique ID: J345
Song Name: Canned Heat
Artist Name: Jamiroquai
Song Length (in seconds): 330

4.
Unique ID: JJ456
Song Name: Black Eagle
Artist Name: Janet Jackson
Song Length (in seconds): 197

5.
Unique ID: SD567
Song Name: I Got The News
Artist Name: Steely Dan
Song Length (in seconds): 306

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

Ex:
ADD SONG
Enter song\'s unique ID: SD123
Enter song\'s name: Peg
Enter artist\'s name: Steely Dan
Enter song\'s length (in seconds): 237

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

Ex:
REMOVE SONG
Enter song\'s unique ID: JJ234
\"All For You\" removed

(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
•   Moving the tail node
•   Moving a node to the head
•   Moving a node to the tail
•   Moving a node up the list
•   Moving a node down the list

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

(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.

Ex:
OUTPUT SONGS BY SPECIFIC ARTIST
Enter artist\'s name: Janet Jackson

2.
Unique ID: JJ234
Song Name: All For You
Artist Name: Janet Jackson
Song Length (in seconds): 391

4.
Unique ID: JJ456
Song Name: Black Eagle
Artist Name: Janet Jackson
Song Length (in seconds): 197

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

Ex:
OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)
Total time: 1461 second

Solution

Note: I couldnt complete the function change() because of time limit.

//Playlist.h

#ifndef _playlist_h

#define _playlist_h

#include<iostream>

#include<string>

using namespace std;

//Node for playlist

class PlaylistNode

{

     string uniqueID;

     string songName;

     string artistName;

     int songLength;

     PlaylistNode* nextNodePtr;

public:

     PlaylistNode();

     PlaylistNode(string id, string sn, string an, int sl);   

     void InsertAfter(PlaylistNode* nn);

     void SetNext(PlaylistNode* nn);

     string GetID() const;

     string GetSongName() const;

     string GetArtistName() const;

     int GetSongLength();

     PlaylistNode* GetNext();

     void PrintPlaylistNode();

};

class Playlist

{

private:

     PlaylistNode *lst;

     int nn=0;

public:

     Playlist();

     void Add(string id, string sn, string an, int sl);

     void Remove(string id);

     void change(int old, int newInd);

     void printSongsByArtist(string an);

     void printTotalTime();

     void printPlaylist();

};

#endif

//Playlist.cpp

#include \"Playlist.h\"

PlaylistNode::PlaylistNode()

{

     nextNodePtr=NULL;

}

PlaylistNode:: PlaylistNode(string id, string sn, string an, int sl)

{

     uniqueID=id;

     songName=sn;

     artistName=an;

     songLength=sl;

}

void PlaylistNode::InsertAfter(PlaylistNode* nn)

{

     nn->SetNext(this);

}

void PlaylistNode::SetNext(PlaylistNode* nn)

{

     nextNodePtr=nn;

}

string PlaylistNode::GetID() const

{

     return uniqueID;

}

string PlaylistNode::GetSongName() const

{

     return songName;

}

string PlaylistNode::GetArtistName() const

{

     return artistName;

}

int PlaylistNode::GetSongLength()

{

     return songLength;

}

PlaylistNode* PlaylistNode::GetNext()

{

     return nextNodePtr;

}

void PlaylistNode::PrintPlaylistNode()

{

     cout<<\"\ Unique ID:\"<<uniqueID<<endl;

     cout<<\"Song Name:\"<<songName<<endl;

     cout<<\"Artist Name:\"<<artistName<<endl;

     cout<<\"Song Length (in seconds):\"<<songLength<<endl;

}

Playlist::Playlist()

{

     lst=NULL;

}

void Playlist::Add(string id, string sn, string an, int sl)

{

     PlaylistNode* newN=new PlaylistNode(id,sn,an,sl);

     newN->SetNext(NULL);

     PlaylistNode *tt=lst;

     if(tt!=NULL)

     {

          while(tt->GetNext()!=NULL)

              tt=tt->GetNext();

    

          tt->SetNext(newN);

     }

     else

     {

          lst=newN;

     }

     nn++;

}

void Playlist::Remove(string id)

{

     PlaylistNode *tt=lst;

     if(tt==NULL)

          return;

     if(tt->GetNext()==NULL)

     {

          delete tt;

          lst=NULL;

     }

     else

     {

          PlaylistNode *pp=tt;

          do

          {

              if(tt->GetID().compare(id)==0)

                   break;

              pp=tt;

              tt=tt->GetNext();

          }while(tt!=NULL);

          pp->SetNext(tt->GetNext());

          cout<<tt->GetSongName()<<\" removed\"<<endl;

          delete tt;

          nn--;

     }

}

void Playlist::change(int old, int newInd)

{

}

void Playlist::printSongsByArtist(string an)

{

     PlaylistNode *pp=lst;

     int kk=0;

     if(pp==NULL)

     {

          cout<<\"Play list empty\"<<endl;

          return;

     }

     while(pp!=NULL)

     {

          kk++;

          if(pp->GetArtistName().compare(an)==0)

          {

              cout<<endl;

              cout<<kk<<endl;

              pp->PrintPlaylistNode();

          }

          pp=pp->GetNext();

     }

}

void Playlist::printTotalTime()

{

     int len=0;                                                                                                                                                             

     PlaylistNode *pp=lst;

     if(pp==NULL)

     {

          cout<<\"Play list empty\"<<endl;

         

     }

     while(pp!=NULL)

     {

          len=len+pp->GetSongLength() ;

         

          pp=pp->GetNext();

     }   

     cout<<\"Total time:\"<<len<<endl;

}

void Playlist::printPlaylist()

{

     PlaylistNode *pp=lst;

     int kk=0;

     if(pp==NULL)

     {

          cout<<\"Play list empty\"<<endl;

          return;

     }

     while(pp!=NULL)

     {

          kk++;

         

          cout<<endl;

          cout<<kk<<endl;

          pp->PrintPlaylistNode();    

          pp=pp->GetNext();

     }

}   

//main.cpp

#include<iostream>

#include<string>

#include<cstdlib>

#include \"Playlist.h\"

using namespace std;

void PrintMenu(string nme)

{

     cout<<\"\ \"<<nme<<\" PLAYLIST 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\"<<endl;

     cout<<\"Choose an option:\"<<endl;

}

int main()

{

     Playlist plst;

     string nme;

     string id;

     string sn;

     string an;

     int len;

     char cc;

     cout<<\"Enter playlist name:\";

     getline(cin,nme);

     while(1)

     {

          PrintMenu(nme);

          cin>>cc;

          cin.ignore();

          if(cc==\'q\')

              break;

          switch(cc)

          {

          case \'a\':

              cout<<\"ADD SONG\"<<endl;

              cout<<\"Enter song\'s unique ID:\";

              getline(cin,id);

              cout<<\"Enter song\'s name:\";

              getline(cin,sn);

              cout<<\"Enter artist\'s name:\";

              getline(cin,an)    ;

              cout<<\"Enter song\'s length(in seconds):\";

              cin>>len;

              plst.Add(id, sn, an, len);

              break;

          case \'d\':

              cout<<\"REMOVE SONG\"<<endl;

              cout<<\"Enter song\'s unique ID:\";

              getline(cin,id);

              plst.Remove(id);

          case \'c\':

              break;

          case \'s\': //art

              cout<<\"OUTPUT SONGS BY SPECIFIC ARTIST\"<<endl;

              cout<<\"Enter artist\'s name: \";

              getline(cin,an);

              plst.printSongsByArtist(an);

              break;

          case \'t\':

cout<<\"OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)\"<<endl;

              plst.printTotalTime();

              break;

          case \'o\':

              cout<<\"\ \"<<nme<<\" - OUTPUT FULL PLAYLIST\"<<endl;

              plst.printPlaylist();

              break;

          default:

              cout<<\"INVALID CHOICE\"<<endl;

          }

     }

     return 0;

}

Sample Output:

Enter playlist name:JAMZ

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:

a

ADD SONG

Enter song\'s unique ID:SJ123

Enter song\'s name:A new song

Enter artist\'s name:New artist

Enter song\'s length(in seconds):295

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:

o

JAMZ - OUTPUT FULL PLAYLIST

1

Unique ID:SJ123

Song Name:A new song

Artist Name:New artist

Song Length (in seconds):295

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:

t

OUTPUT TOTAL TIME OF PLAYLIST (IN SECONDS)

Total time:295

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:

s

OUTPUT SONGS BY SPECIFIC ARTIST

Enter artist\'s name: New artist

1

Unique ID:SJ123

Song Name:A new song

Artist Name:New artist

Song Length (in seconds):295

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:

a

ADD SONG

Enter song\'s unique ID:DK256

Enter song\'s name:A little boy

Enter artist\'s name:Arlen

Enter song\'s length(in seconds):450

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:

o

JAMZ - OUTPUT FULL PLAYLIST

1

Unique ID:SJ123

Song Name:A new song

Artist Name:New artist

Song Length (in seconds):295

2

Unique ID:DK256

Song Name:A little boy

Artist Name:Arlen

Song Length (in seconds):450

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:

d

REMOVE SONG

Enter song\'s unique ID:SJ123

A new song removed

JAMZ PLAYLIST MENU

a - Add song

d - Remove song

c - Change position of song

s - Output songs by specific artist

t - Output total time of playlist (in seconds)

o - Output full playlist

q - Quit

Choose an option:q   

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
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
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
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
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
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
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
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
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
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
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
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
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
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
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site