Question
C++ Pointers [You do not need to do it all] If I could get some help setting up my vector of pointers to the Song
C++ Pointers [You do not need to do it all]
If I could get some help setting up my vector of pointers to the Song class and with what my default constructer should look like. I am quite confused. I will be sure to rate if you help me!
Background
I have a music player on my phone. I can buy songs, add them to playlists and play them. Obviously it would be redundant to store each song in each playlist; each playlist is just a list of pointers to the songs.
For this lab you will simulate this behavior. Your program will need to have options to:
Add songs to the system library (you will store the text of the first line of the song, rather than the audio)
Add playlists
Add songs to a playlist
List playlists
Play a playlist
List all of the songs in the library with a count of how many times each song has been played
Delete a song from a playlist
Delete a playlist
Delete a song from the library (and thus from all playlists that contain it)
Note that we will not be checking many error cases. In real programming this would be bad, you should usually try to recognize and respond to as many types of errors as you can. In the context of class we are trying to acquaint you with as many concepts as possible, so for the sake of educational efficiency we will not be checking most errors in this lab, you may assume that your user provides correct input. You may add all appropriate error testing if you wish, but we will not be testing for it.
Requirements
This lab must be done individually; not with pair programming. See the example below to see the expected formatting.
Part 1 - The Menu (10 points)
Prompt the user to select one of several operations:
add Adds a list of songs to the library list Lists all the songs in the library addp Adds a new playlist addsp Adds a song to a playlist listp Lists all the playlists play Plays a playlist delp Deletes a playlist delsp Deletes a song from a playlist delsl Deletes a song from the library (and all playlists) options Prints this options menu quit Quits the program
After any operation is complete (except for quitting), re-prompt the user to select another operation. If the user enters an unknown option, just print the menu. For part 1, only the quit and options option need work.
Part 2 - Add and display songs (25 points)
For this part you will need to create a song class and vector of pointers to songs. This will be your library of songs.
As songs are added use "new".
At the end of your program free the space for each song using "delete".
Add songs
Prompt the user for the name of the song (you do not need to check for duplicate names).
Prompt the user for the first line of the song.
Initialize the count of how many times this song has been played to 0.
Continue to prompt for songs until the user responds with "STOP".
List all songs - display a list of all of the songs currently in the system and the number of times each song has been played.
Part 3 - Playlists (40 points)
For this part you will need to create a playlist class and a vector of playlists.
Add a playlist
Prompt the user for the name of the playlist (you do not need to check for duplicate names).
Add the new playlist to the vector of playlists.
List a playlist
Add a song to a playlist
List all of the playlists currently in the system and let the user select one of them.
List all of the songs currently in the system and let the user select one of them.
Add a pointer to the selected song into the selected playlist.
Play playlist
List all of the playlist names and let the user select one of them.
"Play" the songs in the play list by printing their first lines.
Whenever a song is played from any playlist, add to the count of how many times it has been played. Note that this is the number of times it has been played, not the number of playlists it is on.
Verify that when you use the "list all songs" operation that the correct count is displayed.
Part 4 - Delete songs and playlists (25 points)
Delete a playlist
Delete a song from a playlist
Note that this does not delete the song from the library
Delete a song from the library. Think about this one!
You will need to first delete the song from any playlist which contains it
You must free the memory that the song object was allocated to (c++ delete)
Then erase it from the library
__________________________________ I have the following so far:
main.cpp
#include
#include
#include "Song.h"
#include "Playlist.h"
using namespace std;
int main()
{
Song song1;
cout << "Welcome to the Firstline Player! Enter options to see menu options." << endl << endl;
string userSelection;
while (userSelection != "quit")
{
cout << "Enter your selection now: ";
cin >> userSelection;
cout << endl;
if (userSelection == "add")
{
song1.add();
}
else if (userSelection == "quit")
{
break;
}
else
{
cout << "add\t Adds a list of songs to the library" << endl;
cout << "list\t Lists all the songs in the library" << endl;
cout << "addp\t Adds a new playlist" << endl;
cout << "addsp\t Adds a song to a playlist" << endl;
cout << "listp\t Lists all the playlists" << endl;
cout << "play\t Plays a playlist" << endl;
cout << "delp\t Deletes a playlist" << endl;
cout << "delsp\t Deletes a song from a playlist" << endl;
cout << "delsl\t Deletes a song from the library (and all playlists)" << endl;
cout << "options\t Prints this options menu" << endl;
cout << "quit\t Quits the program" << endl << endl;
}
}
cout << "Goodbye!" << endl;
return 0;
}
Song.cpp
#include "Song.h"
#include
#include
using namespace std;
vector
string songName;
void Song::SetSongName(string name)
{
songName = name;
}
Song* Song::GetSongPointer(string name)
{
Song* songPointer = 0;
//songPointer = &GetSongName(name);
return songPointer;
}
string Song::GetSongName(string name)
{
return songName;
}
void Song::add()
{
vector
string newSongName;
string songFirstLine;
while (newSongName != "STOP")
{
string* newSongPointer;
int firstTime = 0;
cout << "Song Name: ";
getline(cin, newSongName);
cout << endl;
Song::SetSongName(newSongName);
newSongPointer = &newSongName;
//songFilePoints.push_back();
if (newSongName == "STOP")
{
cout << endl;
break;
}
cout << "Song's First Line: ";
std::getline(cin, songFirstLine);
}
}
Song.h
#include
#ifndef Song_H_
#define Song_H_
using namespace std;
class Song {
public:
//Song();
void SetSongName(string songName);
string GetSongName(string);
Song* GetSongPointer(string);
void add();
//void list();
private:
string songName;
};
#endif
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started