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

c++ please create this class song (song.h file) and a song.cpp file It is very i

ID: 3746714 • Letter: C

Question

c++

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

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

Here is the information about class song.

Class Song

You will also code your own Song class, so you can add Songs to your playlist. 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);

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;

}

thank you

Explanation / Answer

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts. Thanks

//Song.h

#ifndef Song_h

#define Song_h

#include<iostream>

//Song class

class Song{

              private:

              //private attributes

              std::string title_;

              std::string author_;

              std::string album_;

              public:

              //public method prototypes

              Song();

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

              void setTitle(std::string title);

              void setAuthor(std::string author);

              void setAlbum(std::string album);

              std::string getTitle() const;

              std::string getAuthor() const;

              std::string getAlbum() const;

              //friend function prototype for comparing two Song objects

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

};

#endif

//Song.cpp

#include "Song.h"

//implementing all methods

//default constructor

Song::Song(){

              title_="";

              album_="";

              author_="";

}

//parameterized constructor

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

              title_=title;

              author_=author;

              album_=album;

}

//setters

void Song::setTitle(std::string title){

              title_=title;

}

void Song::setAuthor(std::string author){

              author_=author;

}

void Song::setAlbum(std::string album){

              album_=album;

}

//getters

std::string Song::getAlbum() const{

              return album_;

}

std::string Song::getAuthor() const{

              return author_;

}

std::string Song::getTitle() const{

              return title_;

}

//overloaded == operator for comparing two songs

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

              if(lhs.getTitle()==rhs.getTitle() && lhs.getAlbum()==rhs.getAlbum()

                             && lhs.getAuthor()==rhs.getAuthor()){

                             return true;

              }

              return false;

}

/*OUTPUT using the given main() method*/

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

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