Advertisement
Guest User

Untitled

a guest
Dec 11th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1.  
  2. #include "Album.h"
  3. #include "Track.h"
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <sstream>
  8.  
  9. Album::Album()
  10. {
  11.     artist = "";
  12.     title = "";
  13. }
  14.  
  15. Album::Album(string a, string t)
  16. {
  17.     artist = a;
  18.     title = t;
  19. }
  20.  
  21. void Album::setArtist(string a)
  22. {
  23.     artist = a;
  24. }
  25.  
  26. void Album::setTitle(string t)
  27. {
  28.     title = t;
  29. }
  30.  
  31. void Album::setTracklist(vector<Track> tList)
  32. {
  33.     tracks = tList;
  34. }
  35.  
  36. Track Album::getTrack(string title){
  37.     for (vector<Track>::iterator it = tracks.begin(); it != tracks.end(); it++){
  38.         Track& t = *it;
  39.         if (t.getTitle().compare(title) == 0){
  40.             return t;
  41.         }
  42.     }
  43.     Track t1;
  44.     return t1;
  45. }
  46.  
  47. string Album::getArtist() const
  48. {
  49.     return artist;
  50. }
  51.  
  52. string Album::getTitle() const
  53. {
  54.     return title;
  55. }
  56.  
  57. vector<Track>& Album::getTrackList()
  58. {
  59.     return tracks;
  60. }
  61.  
  62. void Album::addTrack(Track t)
  63. {
  64.     tracks.push_back(t);
  65. }
  66.  
  67. Duration Album::totalTime(){
  68.     Duration total;
  69.     for (vector<Track>::iterator it = tracks.begin(); it != tracks.end(); it++){
  70.         Track& t = *it;
  71.         total = total + t.getDuration();
  72.     }
  73.     return total;
  74. }
  75. istream& operator>>(istream& is, Album& a)
  76. {
  77.     string str, artist, title;
  78.  
  79.  
  80.     Track t;
  81.  
  82.     getline(is, str);
  83.  
  84.  
  85.     if (str.find(": ") != -1)
  86.     {
  87.         artist = str.substr(0, (str.find(": ")));
  88.         title = str.substr((str.find(": ")+2));
  89.         a = Album(artist, title);
  90.     }
  91.     if (str.find(" - ") != -1)
  92.     {
  93.         stringstream strStream(str);
  94.         strStream >> t;
  95.         a.addTrack(t);
  96.     }
  97.  
  98.     return is;
  99.  
  100. }
  101.  
  102.  
  103.  
  104.  
  105. bool Album::compareAlbums(const Album* a1,const Album* a2)
  106. {
  107. //return true if a1's artist < a2's artist OR if a1's artist == a2's artist AND a1's title < a2's title
  108.     if (a1->getArtist() == a2->getArtist()){
  109.         return (a1->getTitle() < a2->getTitle());
  110.     }else{
  111.         return a1->getArtist() < a2->getArtist()
  112.     }
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement