Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Album.h"
- #include "Track.h"
- #include <iostream>
- #include <string>
- #include <vector>
- #include <sstream>
- Album::Album()
- {
- artist = "";
- title = "";
- }
- Album::Album(string a, string t)
- {
- artist = a;
- title = t;
- }
- void Album::setArtist(string a)
- {
- artist = a;
- }
- void Album::setTitle(string t)
- {
- title = t;
- }
- void Album::setTracklist(vector<Track> tList)
- {
- tracks = tList;
- }
- Track Album::getTrack(string title){
- for (vector<Track>::iterator it = tracks.begin(); it != tracks.end(); it++){
- Track& t = *it;
- if (t.getTitle().compare(title) == 0){
- return t;
- }
- }
- Track t1;
- return t1;
- }
- string Album::getArtist() const
- {
- return artist;
- }
- string Album::getTitle() const
- {
- return title;
- }
- vector<Track>& Album::getTrackList()
- {
- return tracks;
- }
- void Album::addTrack(Track t)
- {
- tracks.push_back(t);
- }
- Duration Album::totalTime(){
- Duration total;
- for (vector<Track>::iterator it = tracks.begin(); it != tracks.end(); it++){
- Track& t = *it;
- total = total + t.getDuration();
- }
- return total;
- }
- istream& operator>>(istream& is, Album& a)
- {
- string str, artist, title;
- Track t;
- getline(is, str);
- if (str.find(": ") != -1)
- {
- artist = str.substr(0, (str.find(": ")));
- title = str.substr((str.find(": ")+2));
- a = Album(artist, title);
- }
- if (str.find(" - ") != -1)
- {
- stringstream strStream(str);
- strStream >> t;
- a.addTrack(t);
- }
- return is;
- }
- bool Album::compareAlbums(const Album* a1,const Album* a2)
- {
- //return true if a1's artist < a2's artist OR if a1's artist == a2's artist AND a1's title < a2's title
- if (a1->getArtist() == a2->getArtist()){
- return (a1->getTitle() < a2->getTitle());
- }else{
- return a1->getArtist() < a2->getArtist()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement