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

c++ please code Song class, so you can add Songs to your playlist. and a playlis

ID: 3747552 • Letter: C

Question

c++

please code Song class, so you can add Songs to your playlist. and a playlist class

c++

please create this class song (song.h file) and a song.cpp file and a playist.cpp and playlist.h

MOst important is to please expalin the playllist class to me.

It is very important that you write code that is separated in these files.

Here is the information about class song and classplaylist.

THank you

A Song stores the following information (private member variables):

std::string title_;

std::string author_;

std::string album_;

And the following operations (public member functions)

Song();

Song(const std::string& title, const std::string& author = "", const std::string& album = "");

void setTitle(std::string title);  //"set" in setTitle here means "give a value" and has nothing

   // to do with the Set class. Similarly for setAuthor and setAlbum

void setAuthor(std::string author);

void setAlbum(std::string album);

std::string getTitle() const;

std::string getAuthor() const;

std::string getAlbum() const;

friend bool operator==(const Song& lhs, const Song& rhs);

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;

A few things to notice:

The parameterized constructor needs to add a_song to playlist_

Depending on your design/implementation, when removing an item, Set may or may not have preserved an order for the remaining items because in a Set THERE IS NO ORDER. In a PlayList, on the other hand, you may like to have Songs play in a certain order. Don't worry about that for now, although it may not be the most desirable behavior, you can simply remove a Song from the PlayList by calling the Set::remove() member function no matter how you implemented it. We will take care of this in Project 3.

displayPlayList() will take advantage of Set::toVector() to access and display to the console (cout) data for all the songs in playlist_ . For each song it will display: * Title: title * Author: author * Album: album *  on a new line, where the text in red should be replaced by the value of the corresponding Song member variable. After displaying data for all the songs it will display: End of playlist on a new line.

Usage:

Make sure your code compiles and runs correctly with this main() function:

int main() {

  

  //**********Test Song************//

  

  //instantiate 5 songs

  

  Song song1;

  song1.setTitle("title 1");

  song1.setAuthor("author 1");

  song1.setAlbum("album 1");

  

  Song song2("title 2", "author 2", "album 2");

  Song song3("title 3", "author 3", "album 3");

  Song song4("title 4", "author 4", "album 4");

  Song song5("title 5", "author 5", "album 5");

  

  //output song information

  cout << "The first song is: " << song1.getTitle() << ", " << song1.getAuthor() << ", " << song1.getAlbum() << endl;

  cout << "The second song is: " << song2.getTitle() << ", " << song2.getAuthor() << ", " << song2.getAlbum() << endl;

  cout << "The third song is: " << song3.getTitle() << ", " << song3.getAuthor() << ", " << song3.getAlbum() << endl;  

  cout << "The fourth song is: " << song4.getTitle() << ", " << song4.getAuthor() << ", " << song4.getAlbum() << endl << endl;

  //************* Test PlayList*************//

  

  //instantiate PlayList and add Songs to it

  

  PlayList myPlayList(song1);

  myPlayList.addSong(song2);

  myPlayList.addSong(song3);

  myPlayList.displayPlayList();   

  cout << "Playlist now holds " << myPlayList.getNumberOfSongs() << " songs ";

  

  myPlayList.addSong(song1);

  myPlayList.displayPlayList();   

  cout << endl;

  

  myPlayList.addSong(song4);

  

  myPlayList.displayPlayList();

  cout << endl;

  

  myPlayList.addSong(song5);

     myPlayList.displayPlayList();  

     cout << endl;

  

    

  myPlayList.removeSong(song2);

  myPlayList.displayPlayList();   

  cout << endl;

  

  myPlayList.removeSong(song3);

  myPlayList.displayPlayList();

  cout << endl;

  

  myPlayList.clearPlayList();

  myPlayList.displayPlayList();

  cout << myPlayList.isEmpty() << endl;

  

  

  return 0;

}

Thank you

Explanation / Answer

---------------------song.h-------------------

#ifndef SONG_H

#define SONG_H

#include <iostream>

using namespace std;

class Song{

private:

string title_;

string author_;

string album_;

public:

Song();

Song(const string& title, const string& author = "", const string& album = "");

void setTitle(string title); //"set" in setTitle here means "give a value" and has nothing

// to do with the Set class. Similarly for setAuthor and setAlbum

void setAuthor(string author);

void setAlbum(string album);

string getTitle() const;

string getAuthor() const;

string getAlbum() const;

friend bool operator==(const Song& lhs, const Song& rhs);

bool operator< (const Song& x) const;

};

#endif

---------------------song.cpp-------------------

#include "song.h"

#include <iostream>

using namespace std;

//constructor

Song::Song(){

title_ = "" ;

author_ = "";

album_ = "";

}

//paramerterized constructor

Song::Song(const string& title, const string& author, const string& album){

title_ = title ;

author_ = author;

album_ = album;

}

//setter function

void Song::setTitle(string title){

title_ = title ;

}

void Song::setAuthor(string author){

author_ = author;

}

void Song::setAlbum(string album){

album_ = album;

}

//gettter function

string Song::getTitle() const{

return title_;

}

string Song::getAuthor() const{

return author_;

}

string Song::getAlbum() const{

return album_;

}

bool operator==(const Song& lhs, const Song& rhs){

return (lhs.title_ == rhs.title_ && lhs.author_ == rhs.author_ && lhs.author_ == rhs.author_);

}

//this function is mandatory for element insertion as iteratotr in set

bool Song::operator< (const Song& x) const {

return (title_ < x.title_ );

}

---------------------playlist.h-------------------

#ifndef PLAYLIST_H

#define PLAYLIST_H

#include "song.h"

#include <set>

#include <iostream>

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;

};

#endif

---------------------playlist.cpp-------------------

#include "playlist.h"

#include <set>

#include <iostream>

using namespace std;

PlayList::PlayList(){

}

PlayList::PlayList(const Song& a_song){

playlist_.insert(a_song);

}

int PlayList::getNumberOfSongs() const{

return playlist_.size();

}

bool PlayList::isEmpty() const{

return ( playlist_.size() == 0);

}

bool PlayList::addSong(const Song& new_song){

playlist_.insert(new_song);

return true;

}

bool PlayList::removeSong(const Song& a_song){

playlist_.erase(a_song);

return true;

}

void PlayList::clearPlayList(){

playlist_.clear();

}

void PlayList::displayPlayList() const{

cout << "Playlist contains:" <<endl;

for (set<Song>::iterator it=playlist_.begin(); it!=playlist_.end(); ++it)

cout << "* Title" << (*it).getTitle() << " * Author" << (*it).getAuthor() << " * Album" << (*it).getAlbum() << " *" <<endl;

cout << "End of playlist" <<endl;

}

---------------------main.cpp-------------------

#include "playlist.h"

#include <set>

#include <iostream>

using namespace std;

int main() {

  

//**********Test Song************//

  

//instantiate 5 songs

  

Song song1;

song1.setTitle("title 1");

song1.setAuthor("author 1");

song1.setAlbum("album 1");

  

Song song2("title 2", "author 2", "album 2");

Song song3("title 3", "author 3", "album 3");

Song song4("title 4", "author 4", "album 4");

Song song5("title 5", "author 5", "album 5");

  

//output song information

cout << "The first song is: " << song1.getTitle() << ", " << song1.getAuthor() << ", " << song1.getAlbum() << endl;

cout << "The second song is: " << song2.getTitle() << ", " << song2.getAuthor() << ", " << song2.getAlbum() << endl;

cout << "The third song is: " << song3.getTitle() << ", " << song3.getAuthor() << ", " << song3.getAlbum() << endl;  

cout << "The fourth song is: " << song4.getTitle() << ", " << song4.getAuthor() << ", " << song4.getAlbum() << endl << endl;

//************* Test PlayList*************//

  

//instantiate PlayList and add Songs to it

  

PlayList myPlayList(song1);

myPlayList.addSong(song2);

myPlayList.addSong(song3);

myPlayList.displayPlayList();

cout << "Playlist now holds " << myPlayList.getNumberOfSongs() << " songs ";

  

myPlayList.addSong(song1);

myPlayList.displayPlayList();

cout << endl;

  

myPlayList.addSong(song4);

  

myPlayList.displayPlayList();

cout << endl;

  

myPlayList.addSong(song5);

myPlayList.displayPlayList();  

cout << endl;

  

  

myPlayList.removeSong(song2);

myPlayList.displayPlayList();

cout << endl;

  

myPlayList.removeSong(song3);

myPlayList.displayPlayList();

cout << endl;

  

myPlayList.clearPlayList();

myPlayList.displayPlayList();

cout << myPlayList.isEmpty() << endl;

  

  

return 0;

}

----------------output----------------------

The first song is: title 1, author 1, album 1

The second song is: title 2, author 2, album 2

The third song is: title 3, author 3, album 3

The fourth song is: title 4, author 4, album 4

Playlist contains:

* Titletitle 2 * Authorauthor 2 * Albumalbum 2 *

* Titletitle 3 * Authorauthor 3 * Albumalbum 3 *

End of playlist

Playlist now holds 2 songs

Playlist contains:

* Titletitle 1 * Authorauthor 1 * Albumalbum 1 *

* Titletitle 2 * Authorauthor 2 * Albumalbum 2 *

* Titletitle 3 * Authorauthor 3 * Albumalbum 3 *

End of playlist

Playlist contains:

* Titletitle 1 * Authorauthor 1 * Albumalbum 1 *

* Titletitle 2 * Authorauthor 2 * Albumalbum 2 *

* Titletitle 3 * Authorauthor 3 * Albumalbum 3 *

* Titletitle 4 * Authorauthor 4 * Albumalbum 4 *

End of playlist

Playlist contains:

* Titletitle 1 * Authorauthor 1 * Albumalbum 1 *

* Titletitle 2 * Authorauthor 2 * Albumalbum 2 *

* Titletitle 3 * Authorauthor 3 * Albumalbum 3 *

* Titletitle 4 * Authorauthor 4 * Albumalbum 4 *

* Titletitle 5 * Authorauthor 5 * Albumalbum 5 *

End of playlist

Playlist contains:

* Titletitle 1 * Authorauthor 1 * Albumalbum 1 *

* Titletitle 3 * Authorauthor 3 * Albumalbum 3 *

* Titletitle 4 * Authorauthor 4 * Albumalbum 4 *

* Titletitle 5 * Authorauthor 5 * Albumalbum 5 *

End of playlist

Playlist contains:

* Titletitle 1 * Authorauthor 1 * Albumalbum 1 *

* Titletitle 4 * Authorauthor 4 * Albumalbum 4 *

* Titletitle 5 * Authorauthor 5 * Albumalbum 5 *

End of playlist

Playlist contains:

End of playlist

1

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