Question: #include playlist.h Playlist::Playlist ( ) { firstSong = lastSong = nullptr; / / if using default, nothing in queue numberSongsLoaded = 0 ; name

#include "playlist.h"
Playlist::Playlist(){
firstSong = lastSong = nullptr; //if using default, nothing in queue
numberSongsLoaded =0;
name = "Playlist";
}
Playlist::Playlist(Song* f, Song* l, int n, string nm){
//left in to showcase moving through a queue
//this WILL NOT compile until the underlined methods are implemented
numberSongsLoaded =n;
name = nm;
if(f == nullptr){
firstSong = lastSong = nullptr;
return;
}
Song* temp = f;
firstSong = lastSong = new Song;
firstSong->setArtist(temp->getArtist());
firstSong->setTitle(temp->getTitle());
firstSong->setNextSong(nullptr);
temp = temp->getNextSong();
while(temp != nullptr){
lastSong->setNextSong(new Song);
lastSong = lastSong->getNextSong();
lastSong->setArtist(temp->getArtist());
lastSong->setTitle(temp->getTitle());
lastSong->setNextSong(nullptr);
temp = temp->getNextSong();
}
}
//write a copy constructor
//this will look very similar to the parameretized constructor
Playlist::Playlist(const Playlist& rhs){
firstSong =rhs.firstSong;
lastSong = rhs.lastSong;
numberSongsLoaded = rhs.numberSongsLoaded;
name= rhs.name;
Song* temp = rhs.firstSong;
while(temp!= nullptr){
*this +*temp;
temp = temp->getNextSong();
}
}
//write a desctructor
//this will iterate through playlist and delete all items
Playlist::~Playlist(){
while (firstSong != nullptr){
deleteSongFromEnd();
}
}
//getters
string Playlist::getName(){
return name;
}
//setters
void Playlist::setName(string nm){
name = nm;
}
//write a method to check if song is already in playlist
//will iterate through queue and check a passed song against songs already in playlist
bool Playlist::isSongInPlaylist(const Song& song)const{
Song* temp = firstSong;
while(temp != nullptr){
if(temp->getTitle()== song.getTitle()&&temp->getArtist()== song.getArtist()){
return true;
}
temp = temp ->getNextSong();
}
return false;
}
//will
//create the public adder method
//this should add a song at the beginning of the playlist
void Playlist::addSongAtBeginning(const Song& song){
Song* newSong = new Song(song);
newSong->setNextSong(firstSong);
firstSong = newSong;
if (lastSong == nullptr){
lastSong = firstSong;
}
numberSongsLoaded++;
}
//create the private delete method
//this should delete the song at the end of the playlist
//check if there are no songs left in the playlist
void Playlist::deleteSongFromEnd(){
if(firstSong == nullptr);
return;
if(firstSong ==lastSong){
delete firstSong;
firstSong = lastSong = nullptr
}else{
Song* temp = firstSong;
while(temp ->getNextSong()!= lastSong){
temp = temp->getNextSong();
}
delete lastSong;
lastSong = temp;
lastSong->setNextSong(nullptr);
}
numberSongsLoaded--;
}
//create the public delete method
//delete song at specific index position
void Playlist::deleteSongAt(int i){
if(i <0|| i >= numberSongsLoaded);
return;
if(i ==0){
Song* temp = firstSong;
firstSong = firstSong->getNextSong();
delete temp;
if(firstSong == nullptr){
lastSong = nullptr;
}else{
Song* prev = firstSong;
for(int i =0; igetNextSong();
}
}
Song* temp = prev->getNextSong();
prev ->setNextSong(temp ->getNextSong());
if(temp == lastSong);
lastSong =prev;
delete temp;
}
numberSongsLoaded--;
}
//create a method that gets a song at a specific index position
//this will be used in the delete and adder methods
Song* Playlist::getSongAt(int i)const{
if(i <0|| i>= numberSongsLoaded);
return nullptr;
Song* temp = firstSong;
for(int i =0; i< index; i++){
temp = temp->getNextSong();
}
return temp;
}
void Playlist::displayLoadedSongs(bool displayNumbers)const{
if(firstSong == nullptr){
cout <<"No songs are currently loaded for play." <getTitle()<< endl;
temp = temp->getNextSong();
numDisp+=1;
}
}
Playlist& Playlist::operator=(const Playlist& rhs){
//include a return *this
firstSong =rhs.rhsfirstSong;
lastSong = rhs.lastSong;
numberSongsLoaded = rhs.numberSongsLoaded;
name= rhs.name;
Song*

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!