How to use functions from the class members in main
Apr 13, 2017 at 1:59am UTC
I am making this program simulates an ipod and has songs and makes playlists. We are using lots of pointers which I understand them but not necessarily how to incorporate them. My problem right now is that when i print the list you have to print the song name and first line. How do i access my GetName and GetFirstline function to print it out? Is that even possible?
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
#include <iostream>
#include <vector>
#include <string>
#include "Song.h"
#include "Playlist.h"
using namespace std;
void PrintMenu(){
cout << "Please select one of the following options: " << endl;
cout << endl;
cout << "0 - Quit the program" << endl;
cout<< "1 - Add songs" << endl;
cout << "2 - List all songs" << endl;
cout << "3 - Add a playlist" << endl;
cout << "4 - Add a song to a playlist" << endl;
cout << "5 - Play a playlist" << endl;
cout << endl;
cout << "Enter your selection now: " << endl;
}
vector <Song*>AddSong() {
string songName;
string songFirstLine;
vector<Song*> songs;
cout << "Read in Song names and first lines: " << endl;
while (true ) {
cout << "Song Name (type \"STOP\" when done): " << endl;
cout << endl;
getline (cin, songName);
if (songName == "STOP" ) {
break ;
}
cout << "That song's first line: " << endl;
getline(cin, songFirstLine);
Song* song = new Song(songName, songFirstLine);
songs.push_back(song);
}
return songs;
}
void PrintSongList(vector<Song*> songs) {
int count = 0;
for (unsigned int i=0; i < songs.size(); i++) {
cout << i << ": " << "Name: \"" << songs.at(i) << "\" FirstLine: \"" << songs.at(i) << "\" Played " << count << " times." << endl;
}
}
int main() {
int menuOption;
vector <Song*> songs;
cout <<"Welcome to the Firstline Player!" << endl;
cout << endl;
cout << endl;
do {
PrintMenu();
cin >> menuOption;
cin.ignore();
switch (menuOption){
case 0:
cout << "GOODBYE!" << endl;
return 0;
case 1: {
vector<Song*> songsList = AddSong();
songs.insert(songs.end(), songsList.begin(), songsList.end());
break ;
}
case 2:
PrintSongList(songs);
break ;
/*case 3:
break;
case 4:
break;
case 5:
break;
default:
*/
}
}while (menuOption == true );
return 0;
}
Last edited on Apr 15, 2017 at 11:11pm UTC
Topic archived. No new replies allowed.