Store your songs and playlists in std::vector. This doesn't restrict your lists to a limited size.
Below I have made a short example which shows you how to handle your strucs.
#include <iostream>
#include <vector>
#include <string>
struct Song
{
std::string title;
std::string artist;
double length;
};
struct Playlist
{
std::string title;
std::string artist;
std::string genre;
double length;
std::vector<Song*> songList;
void addSong( Song * song ) {
songList.push_back( song );
length += song->length;
}
};
std::vector<Song> mySongs;
std::vector<Playlist> myPlaylists;
int main()
{
// how to add a song into mySongs:
// 1) create a song-object
std::string title, artist, length;
std::getline(std::cin, title); // getline reads a whole line
std::getline(std::cin, artist);
std::getline(std::cin, length);
Song song;
song.title = title;
song.artist = artist;
song.length = std::stod(length);
// 2) store your song-object
mySongs.push_back( song );
// how to add a song to a Playlist
Playlist myPlaylist;
myPlaylist.addSong( &song ); // uses the song object created above
// how to show the song's data in a playlist:
for (auto song : myPlaylist.songList)
{
std::cout << "title:"
<< song->title
<< " artist:"
<< song->artist
<< " length: "
<< song->length
<< std::endl;
}
}
I hope this helps you understanding how structs get filled and stored.
Consider that here in this example all songs are stored in a std::vector<Songs> container. In a std::vector<Playlist> container there will merely stored pointers to the songs.
If still something is unclear to you, don't hesitate to ask.
#ifndef MY_SONG_CLASS
#define MY_SONG_CLASS
#include <string>
class Song {
private:
public:
//member variables
std::string songTitle;
std::string artistName;
std::string songGenre;
double songLength {0.0};
// functions
Song();
Song(const std::string& title, const std::string& artist,
const std::string& genre, double length);
// Sets a name for the song
void setSongTitle(const std::string& st);
// Sets the artist name of the song
void setArtistName(const std::string& ar);
// Sets the album name of the song
void setSongGenre(const std::string& sg);
//Sets the song length of the song
void setSongLength(double sl);
// Gets the name of the song
std::string getSongName();
// Gets the name of the artist
std::string getArtistName();
// Gets the album name of the song
std::string getSongGenre();
//Gets the song length of the song
double getSongLength();
};
#endif // MY_SONG_CLASS