Reference no: EM13163590
The CD object should have a data member that is a linked list of your song structure that you have in CD. The CD class needs a function that allows it to add a song to the object, that function would then append the song to that instance of the linked list (the one with the structure). Then once all the songs are added then you append it to the CD list in main. There should not be a variable called songs that is global. You will need a copy constructor that will copy the songs in the list in the class, if not then it will not append the songs list when you append it to the list in main.
// This class uses a linked list to keep track of the
// titles of songs on a CD. It also maintains the
// length and title of each song.
class CD : public Media
{
private:
string artist; // To hold the artist name
public:
// Declare a struct
struct Song
{
string title;
double length;
}my_disc;
CD();
CD(string);
CD(string, string, double);
// Mutators
void setArtist(string);
// Accessors
string getArtist();
// Overloaded operators
bool operator == (const CD &e);
bool operator != (const CD &e);
};
#endif
#include "CD.h"
//*********************************************************
// Default constructor initalizes the data member. It also*
// calls the base constructor *
//*********************************************************
CD::CD() : Media()
{
artist = "";
}
//*********************************************************
// Default constructor sets the data member artist. It *
// also calls the base constructor and passes name and *
// length as arguments *
//*********************************************************
CD::CD(string a, string n, double l ) : Media(n, l)
{
artist = a;
}
//*********************************************************
// setArtist accepts a parameter as an argument and sets *
// the data member *
//*********************************************************
void CD::setArtist(string a)
{
artist = a;
}
//*********************************************************
// getArtist returns the artist *
//*********************************************************
string CD::getArtist()
{
return artist;
}
//*********************************************************
// Overloaded == operator compares the artist *
// with that of the parameter *
//*********************************************************
bool CD::operator == (const CD &e)
{
if (artist == e.artist)
return true;
return false;
}
//*********************************************************
// Overloaded != operator compares the artist *
// with that of the parameter *
//*********************************************************
bool CD::operator != (const CD &e)
{
if (artist != e.artist)
return true;
return false;
}