Question

In: Computer Science

Create a class that will store all the information needed for a song. Your class will...

Create a class that will store all the information needed for a song. Your class will store the following data:

  • A string for the song title.
  • A string for the Artist/Band title
  • A string for the Album/Compilation Name
  • A string for the Genre
  • A boolean called liked that represents whether you like the song

The class will have the following methods:

  • A constructor that will make a Song object from a song title, artist and album name
  • A constructor that will make a Song object from only the song title and artist
  • string to_string()// Will return a string that will have the name artist and album of the song
  • void play)() // A function that will print out the song title, artists, and album name using your
  • void set_liked(bool song_vote) //Will save the fact that you've liked a song
  • bool get_liked()//Will return a true or false value representing whether you like the song or not
  • string get_artist()//will return you a string with the artist name
  • void set_artist(string name)//will set the artists name for the song to the string you pass into the function
  • You should also create set and get methods rest of the variables in the class e.g.: song_title and genre

Your program should have a main that creates three song objects, places them into a vector and uses a for loop to "play" each of the songs using your play method.

Solutions

Expert Solution

Answer:-

Hello, I have written the required code in CPP. Please find it below.

CPP CODE:-

#include <iostream>
#include <string>
#include <vector>
using namespace std;
/* song class starts here*/
class song
{
   /* Data members of song class*/
   string title;
   string artist;
   string album;
   string genre;
   bool liked;
  
   public:
   /* Constructors for song class*/  
       song(string title, string artist, string album)
       {
           this->title=title;
           this->artist=artist;
           this->album=album;
       }
   song(string title,string artist)
   {
       this->title=title;
           this->artist=artist;
      
       }
   /* Implementation of to_string function*/  
       string to_string()
       {
       return "Artist Name = "+artist+" Album Name = "+album;
       }
   /* Implementation of play function*/  
       void play()
       {
           cout<<"Song Title = "<<title<<" Artist = "<<artist<<" Album Name = "<<album<<endl;
          
       }
   /* getters and setters*/  
       void set_liked(bool song_vote)
       {
           liked=song_vote;
       }
       bool get_liked()
       {
           return liked;
       }
       string get_artist()
       {
           return artist;
       }
       void set_artist(string name)
       {
           artist=name;
       }
           string get_title()
       {
           return title;
       }
       void set_title(string title)
       {
           this->title=title;
       }
           string get_album()
       {
           return album;
       }
       void set_album(string album)
       {
           this->album=album;
       }
           string get_genre()
       {
           return genre;
       }
       void set_genre(string genre)
       {
           this->genre=genre;
       }
      
};
/* main function starts here*/
int main()
{
   vector < song > a ;
   /* Declaration of 3 song objects*/
   song song1("AAA","Artist1","Album1");
   song song2("BBB","Artist2","Album2");
   song song3("CCC","Artist2","Album3");
   a.push_back(song1);
   a.push_back(song2);
   a.push_back(song3);
   /* Using for loop for calling play() function for all songs*/
   for(int i=0; i < a.size(); i++)
a.at(i).play() ;
}

Screenshot of the code:-

Please refer to the screenshot of the code for proper understanding the indentation of the code.

Screenshot 1:-

Screenshot 2:-

Screenshot 3:-

OUTPUT:-

I hope, it would help.

Thanks!


Related Solutions

Create a class, called Song. Song will have the following fields:  artist (a string) ...
Create a class, called Song. Song will have the following fields:  artist (a string)  title (a string)  duration (an integer, recorded in seconds)  collectionName (a string) All fields, except for collectionName, will be unique for each song. The collectionName will have the same value for all songs. In addition to these four fields, you will also create a set of get/set methods and a constructor. The get/set methods must be present for artist, title, and duration....
Create a Class to contain a customer order Create attributes of that class to store Company...
Create a Class to contain a customer order Create attributes of that class to store Company Name, Address and Sales Tax. Create a public property for each of these attributes. Create a class constructor without parameters that initializes the attributes to default values. Create a class constructor with parameters that initializes the attributes to the passed in parameter values. Create a behavior of that class to generate a welcome message that includes the company name. Create a Class to contain...
// The Song class that represents a song // Do not make any changes to this...
// The Song class that represents a song // Do not make any changes to this file! public class Song { // instance variables private String m_artist; private String m_title; private Song m_link; // constructor public Song(String artist, String title) { m_artist = artist; m_title = title; m_link = null; } // getters and setters public void setArtist(String artist) { m_artist = artist; } public String getArtist() { return m_artist; } public void setTitle(String title) { m_title = title; }...
You are given the following class definition (assume all methods are correctly implemented): public class Song...
You are given the following class definition (assume all methods are correctly implemented): public class Song { ... public Song(String name, String artist) { ... } public String getName() { ... } public String getArtist() { ... } public String getGenre() { ... } public int copiesSold() { ... } } Write NAMED and TYPED lambda expressions for each of the following, using appropriate functional interfaces from the java.util.function and java.util packages (Only the lambda expression with no type+name will...
You are given the following class definition (assume all methods are correctly implemented): public class Song...
You are given the following class definition (assume all methods are correctly implemented): public class Song { ... public Song(String name, String artist) { ... } public String getName() { ... } public String getArtist() { ... } public String getGenre() { ... } public int copiesSold() { ... } } Write NAMED and TYPED lambda expressions for each of the following, using appropriate functional interfaces from the java.util.function and java.util packages (Only the lambda expression with no type+name will...
Create a Square Class and Create a graphical representation of your Square class - your class...
Create a Square Class and Create a graphical representation of your Square class - your class will have the following data fields: double width, String color. - provide a no-args constructor. - provide a constructor that creates a square with the specific width - implement method getArea() - implement method getPerimeter() - implement method setColor(). - draw a UML diagram for your class - write a test program that will create a square with the width 30, 40 and 50....
In java Create a class named CellPhoneCase that extends your Case class – it inherits all...
In java Create a class named CellPhoneCase that extends your Case class – it inherits all the fields and methods from the Case class. It should also contain:  One field for a CellPhone object. Be sure to put in the appropriate access modifier. (private, public)  A constructor with 3 parameters – owner’s name, Case color, the phone number of the cell phone that will be in the Case. This constructor MUST call the super class’s constructor. Then set...
Create a class Ledger that will record the sales for a store. It will have the...
Create a class Ledger that will record the sales for a store. It will have the attributes ■ sale—an array of double values that are the amounts of all sales ■ salesMade—the number of sales so far ■ maxSales—the maximum number of sales that can be recorded and the following methods: ■ Ledger(max)—a constructor that sets the maximum number of sales to max ■ addSale(d)—adds a sale whose value is d ■ getNumberOfSales—returns the number of sales made ■ getTotalSales—returns...
Write a Java program that implements a song database. The SongsDatabase class keeps tracks of song...
Write a Java program that implements a song database. The SongsDatabase class keeps tracks of song titles by classifying them according to genre (e.g., Pop, Rock, etc.). The class uses a HashMap to map a genre with a set of songs that belong to such a genre. The set of songs will be represented using a HashSet. Your driver output should sufficiently prove that your code properly implements the code below. public class SongsDatabase { private Map<String, Set<String>> genreMap =...
Using doubly linked list in c++ with class constructor: DNode(){    song = Song();    prev...
Using doubly linked list in c++ with class constructor: DNode(){    song = Song();    prev = NULL;    next = NULL; } DNode(string s, string a, int lenmin, int lensec){    song = Song(s,a,lenmin,lensec);    prev = NULL;    next = NULL; } for each node. Write the method: void moveUp(string t); This method moves a song up one in the playlist. For instance, if you had the following: Punching in a Dream, The Naked And Famous................3:58 Harder To...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT