-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlaylistmain.cpp
226 lines (199 loc) · 6.26 KB
/
Playlistmain.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
#include "Playlist.h"
#include <iostream>
#include <string>
using namespace std;
void printOptions();
void addListOfSongsToLibrary(vector<Song*>& songs);
void listAllSongsInLibrary(vector<Song*> songs);
void addPlaylist(vector<Playlist>& playlists);
void addSongToPlaylist(vector<Playlist>& playlists, vector<Song*> songs);
void listAllPlaylists(vector<Playlist> playlists);
void playPlaylist(vector<Playlist> playlists);
void deletePlaylist(vector<Playlist>& playlists);
void deleteSongFromPlaylist(vector<Playlist>& playlists);
void deleteSongFromLibraryAndAllPlaylists(vector<Playlist>& playlists, vector<Song*>& songs);
void listAllSongs(vector<Song*> songs);
int main()
{
string choice;
vector<Song*> songs;
vector<Playlist> playlists;
string temp;
cout << "Welcome to the Firstline Player! Enter options to see menu options." << endl << endl;
do
{
cout << endl << "Enter your selection now: ";
cin >> choice;
getline(cin, temp);
if (choice.compare("add") == 0)
{
addListOfSongsToLibrary(songs);
}
else if (choice.compare("list") == 0)
{
listAllSongsInLibrary(songs);
}
else if (choice.compare("addp") == 0)
{
addPlaylist(playlists);
}
else if (choice.compare("addsp") == 0)
{
addSongToPlaylist(playlists, songs);
}
else if (choice.compare("listp") == 0)
{
listAllPlaylists(playlists);
}
else if (choice.compare("play") == 0)
{
playPlaylist(playlists);
}
else if (choice.compare("remp") == 0)
{
deletePlaylist(playlists);
}
else if (choice.compare("remsp") == 0)
{
deleteSongFromPlaylist(playlists);
}
else if (choice.compare("remsl") == 0)
{
deleteSongFromLibraryAndAllPlaylists(playlists, songs);
}
else if (choice.compare("options") == 0)
{
printOptions();
}
else if (choice.compare("quit") == 0)
{
for (unsigned int i = 0; i < songs.size(); ++i)
{
delete songs.at(i);
}
cout << "Goodbye!" << endl;
}
else
{
printOptions();
}
} while (choice.compare("quit") != 0);
cout << endl << endl;
return 0;
}
void printOptions()
{
cout << endl;
cout << "add Adds a list of songs to the library" << endl;
cout << "list Lists all the songs in the library" << endl;
cout << "addp Adds a new playlist" << endl;
cout << "addsp Adds a song to a playlist" << endl;
cout << "listp Lists all the playlists" << endl;
cout << "play Plays a playlist" << endl;
cout << "remp Removes a playlist" << endl;
cout << "remsp Removes a song from a playlist" << endl;
cout << "remsl Removes a song from the library (and all playlists)" << endl;
cout << "options Prints this options menu" << endl;
cout << "quit Quits the program" << endl;
}
void addListOfSongsToLibrary(vector<Song*>& songs)
{
string songName;
string songFirstLine;
cout << "Enter songs' names and first lines (type \"DONE\" when done):";
cout << endl << "Song Name: ";
getline(cin, songName);
while (songName.compare("DONE") != 0)
{
cout << endl << "Song's first line: ";
getline(cin, songFirstLine);
Song* pointer = new Song(songName, songFirstLine, 0);
songs.push_back(pointer);
cout << endl << "Song Name: ";
getline(cin, songName);
}
}
void listAllSongsInLibrary(vector<Song*> songs)
{
for (unsigned int i = 0; i < songs.size(); ++i)
{
cout << songs.at(i)->getSongName() << ": \"" << songs.at(i)->getFirstLine() << "\", "
<< songs.at(i)->getPlayedCount() << " play(s)." << endl;
}
}
void addPlaylist(vector<Playlist>& playlists)
{
string playlistName;
cout << "Playlist name: ";
getline(cin, playlistName);
playlists.push_back(playlistName);
}
void addSongToPlaylist(vector<Playlist>& playlists, vector<Song*> songs)
{
int songIndex = 0;
int playlistIndex = 0;
listAllPlaylists(playlists);
cout << "Pick a playlist index number: ";
cin >> playlistIndex;
listAllSongs(songs);
cout << "Pick a song index number: ";
cin >> songIndex;
(playlists.at(playlistIndex)).addSong(songs.at(songIndex));
}
void listAllPlaylists(vector<Playlist> playlists)
{
for (unsigned int i = 0; i < playlists.size(); ++i)
{
cout << " " << i << ": " << (playlists.at(i)).getPlaylistName() << endl;
}
}
void playPlaylist(vector<Playlist> playlists)
{
int playlistIndex = 0;
listAllPlaylists(playlists);
cout << "Pick a playlist index number: ";
cin >> playlistIndex;
cout << endl << "Playing songs from playlist: " << (playlists.at(playlistIndex)).getPlaylistName() << endl;
(playlists.at(playlistIndex)).printPlaylist();
}
void deletePlaylist(vector<Playlist>& playlists)
{
int playlistIndex = 0;
listAllPlaylists(playlists);
cout << "Pick a playlist index number to remove: ";
cin >> playlistIndex;
playlists.erase(playlists.begin() + playlistIndex);
}
void deleteSongFromPlaylist(vector<Playlist>& playlists)
{
int songIndex = 0;
int playlistIndex = 0;
listAllPlaylists(playlists);
cout << "Pick a playlist index number: ";
cin >> playlistIndex;
listAllSongs(playlists.at(playlistIndex).getSongs());
cout << "Pick a song index number to remove: ";
cin >> songIndex;
Song* s = playlists.at(playlistIndex).getSongs().at(songIndex);
(playlists.at(playlistIndex)).removeSong(s);
}
void deleteSongFromLibraryAndAllPlaylists(vector<Playlist>& playlists, vector<Song*>& songs)
{
int songIndex = 0;
listAllSongs(songs);
cout << "Pick a song index number to remove: ";
cin >> songIndex;
Song* s = songs.at(songIndex);
for (unsigned int i = 0; i < playlists.size(); i++)
{
playlists.at(i).removeSong(s);
}
songs.erase(songs.begin() + songIndex);
}
void listAllSongs(vector<Song*> songs)
{
for (unsigned int i = 0; i < songs.size(); ++i)
{
cout << " " << i << ": " << songs.at(i)->getSongName() << endl;
}
}