#include #include "computer.h" // Add an MP3 to the list of MP3s. Return false if the song is already there. bool Computer::add_mp3(const string& artist, const string& title) { list::iterator p; for (p = mp3s_.begin(); p != mp3s_.end(); ++p) { if (p->get_artist() == artist && p->get_title() == title) break; } if (p != mp3s_.end()) { return false; } else { mp3s_.push_back(MP3(artist, title)); return true; } } // Iterate through the list of MP3, printing each. void Computer::print_mp3s() const { for(list::const_iterator p = mp3s_.begin(); p != mp3s_.end(); ++p) { cout << " ARTIST: " << p->get_artist() << endl << " TITLE: " << p->get_title() << endl; } } // Returns true if the Computer has the requested song, returns reference to song via parameter bool Computer::has_song(const string& artist, const string& title, MP3& requested_song) const { for (list::const_iterator p = mp3s_.begin(); p != mp3s_.end(); ++p) { if (p->get_artist() == artist && p->get_title() == title) { requested_song = *p; return true; } } return false; } // Build a list of all songs by the indicated artist. list Computer::songs_by_artist(const string& artist) const { list results; for(list::const_iterator p = mp3s_.begin(); p != mp3s_.end(); ++p) { if (p->get_artist() == artist) results.push_back(*p); } return results; }