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

Given PlayList.h please help me write PlaylList.cpp Class PlayList Your PlayList

ID: 3744368 • Letter: G

Question

Given PlayList.h please help me write PlaylList.cpp

Class PlayList

Your PlayList class will have a single data member (private member variable), a Set object called playlist_ which will store your Songs:

Set<Song> playlist_;

Your PlayList will have the following operations (public member functions)

PlayList();

PlayList(const Song& a_song);

int getNumberOfSongs() const;

bool isEmpty() const;

bool addSong(const Song& new_song);

bool removeSong(const Song& a_song);

void clearPlayList();

void displayPlayList() const;

Explanation / Answer

-----------------------PlayList.h---------------------

#include<iostream>

#include <set>

#include <iterator>

using namespace std;

class PlayList{

   

    private:

       

        set<Song> playlist_;

       

    public:

       

        PlayList();

        PlayList(const Song& a_song);

        int getNumberOfSongs() const;

        bool isEmpty() const;

        bool addSong(const Song& new_song);

        bool removeSong(const Song& a_song);

        void clearPlayList();

        void displayPlayList() const;

};

-----------------------------PlayList.cpp-----------------------------

#include "PlayList.h"

#include<set>

#include<iterator>

// constructor

PlayList::PlayList()

{

   

}

// constructor

PlayList::PlayList(const Song& a_song)

{

    // insert() funciton adds the element to the set

    this->playlist_.insert( a_sing );

}

int PlayList::getNumberOfSongs() const

{

    // size() function returns the no of elements in a set

    return this->playlist_.size();

}

bool PlayList::isEmpty() const

{

    // if the set is empty

    if( this->playlist_.size() == 0 )

        return true;

       

    return false;

}

bool PlayList::addSong(const Song& new_song)

{

    // insert() funciton adds the element to the set

    this->playlist_.insert( new_song );

}

// a_song is the object to be removed

bool PlayList::removeSong(const Song& a_song)

{

    // create an iterator to Set<Song> type

    set<Song>::iterator itr;

   

    // traverse through the set

    for( itr = this->playlist_.begin() ; itr != this->playlist_.end() ; itr++ )

    {

        // if the current element is to be removed

        // please change this according to the comparison to be made as per the Song class

        if( *itr == a_song )

        {

            // erase function removes the element pointed by itr

            this->playlist_.erase( itr );

           

            break;

        }

    }

}

void PlayList::clearPlayList()

{

    // clear function removes all elements from set

    this->playlist_.clear();

}

void PlayList::displayPlayList() const

{

    // create an iterator to Set<Song> type

    set<Song>::iterator itr;

   

    // traverse through the set

    for( itr = this->playlist_.begin() ; itr != this->playlist_.end() ; itr++ )

        // please change the cout according to the Song class

        cout<<*itr<<" ";

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote