#include #include #include #include "song.h" using namespace std; // show all songs in a vector of songs void ShowSongs (const vector & all) { int num = all.size(); for (int cnt = 0; cnt < num; cnt++) { cout << all[cnt] << endl; } return; } // ask yes no question - not allowing to continue until y/Y/n/N entered // returns a lower case y or n (always! nothing else) char askYN (const string & prompt) { char answ; // (loop until they give us a valid answer to the question) do { // ask for and get answer cout << prompt << " (y or n): " << flush; cin >> answ; // force all to lower case to simplify while test below if (answ == 'Y') answ = 'y'; if (answ == 'N') answ = 'n'; } while ((answ != 'n') && (answ != 'y')); return answ; } // MAR istream& mygetline(istream &strIn, string &newVal, char toStop = '\n') { char curr; newVal = ""; curr = getchar(); // skip leading "white space" - new line blank while ((curr == ' ') || (curr == '\n')) { curr = getchar(); } // now get real chars while (curr != toStop) { newVal += curr; curr = getchar(); } return strIn; } int main() { vector allSongs(10); ShowSongs(allSongs); cout << "allSongs empty? " << allSongs.empty() << endl; Song myDummy("Default","Nobody",0,0); Song leaving("Leaving Las Vegas", "Cheryl Crow",4,25); vector dummys(5,myDummy); cout << "Dummy: " << endl; ShowSongs(dummys); vector mt; cout << "Empty: " << endl; ShowSongs(mt); cout << "mt empty? " << mt.empty() << endl; vector copy (dummys); cout << "Copy: " << endl; ShowSongs(copy); char stopnow; cin >> stopnow; char cont; do { string newTitle; string newArtist; int newMins; int newSecs; cout << "Enter the song title: " << flush; mygetline(cin,newTitle,'\n'); cout << "Enter the artist: " << flush; mygetline(cin,newArtist,'\n'); cout << "Enter the song time in whole minutes " << flush; cin >> newMins; cout << "Now enter seconds " << flush; cin >> newSecs; Song newSong(newTitle,newArtist,newMins,newSecs); mt.push_back(newSong); cout << endl << "Current Songs: " << endl; ShowSongs(mt); cont = askYN("Do you want to continue adding songs?"); } while (cont == 'y'); cout << "Front of mt: " << mt.front() << endl; return 0; }