Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.34 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <fstream>
  4. #include <string>
  5. #include <vector>
  6. #include <map>
  7. #include <algorithm>
  8. #include <iterator>
  9. #include <conio.h>
  10.  
  11.  
  12. using namespace std;
  13.  
  14.  
  15. class Music_Player
  16. {
  17. private:
  18.    
  19. public:
  20.    
  21.    
  22.     struct track
  23.     {
  24.     private:
  25.        
  26.  
  27.     public:
  28.  
  29.         int YearConvertFromString(string a)
  30.         {
  31.             int res = 0;
  32.             int crt = 0;
  33.             if (a[0] == '+')
  34.                 crt++;
  35.  
  36.             for (int i = crt; i < a.size(); i++)
  37.                 if (isdigit(a[i]))
  38.                     res = (res * 10) + (a[i] - '0');
  39.                 else
  40.                     return -1;
  41.             return res;
  42.         };
  43.        
  44.         string track_name;
  45.        
  46.  
  47.         string performer;
  48.         int year_of_execution;
  49.         track()
  50.         {
  51.             performer = "unknown";
  52.             track_name = "unknown";
  53.             year_of_execution = -1;
  54.         };
  55.  
  56.         track(string default)
  57.         {
  58.             performer = "unknown";
  59.             track_name = default;
  60.             year_of_execution = -1;
  61.         }; 
  62.  
  63.         track(int in_year_of_execution)
  64.         {
  65.             performer = "unknown";
  66.             track_name = "unknown";
  67.             year_of_execution = in_year_of_execution;
  68.         };
  69.  
  70.         track(string default, int in_year_of_execution)
  71.         {
  72.             performer = "unknown";
  73.             track_name = default;
  74.             year_of_execution = in_year_of_execution;
  75.         }
  76.  
  77.         track(string in_performer, string in_track_name)
  78.         {
  79.             performer = in_performer;
  80.             track_name = in_track_name;
  81.             year_of_execution = -1;
  82.         };
  83.  
  84.         track(string in_performer, string in_track_name, int in_year_of_execution)
  85.         {
  86.             performer = in_performer;
  87.             track_name = in_track_name;
  88.             year_of_execution = in_year_of_execution;
  89.         };
  90.  
  91.        
  92.  
  93.         void getTrackFromString(string strInTrackList)
  94.         {
  95.             string prsm;
  96.             int i = 0;
  97.             int end = strInTrackList.length();
  98.             int gapFlag = 1;
  99.  
  100.             while ((gapFlag == 1) && (i < end))
  101.             {
  102.                 performer += strInTrackList[i];
  103.                 if ((strInTrackList[i] == ' ') && (strInTrackList[i + 1] == '-'))
  104.                 {
  105.                     gapFlag = 2;
  106.                     i += 3;
  107.                     break;
  108.                 }
  109.  
  110.                 if ((strInTrackList[i] == ' ') && (strInTrackList[i + 1] == '['))
  111.                 {
  112.                     gapFlag = 3;;
  113.                     i += 3;
  114.                     break;
  115.                 }
  116.             }
  117.  
  118.             while ((gapFlag == 2) && (i < end))
  119.             {
  120.                 track_name += strInTrackList[i];
  121.                 if ((strInTrackList[i] == ' ') && (strInTrackList[i + 1] == '['))
  122.                 {
  123.                     gapFlag = 3;;
  124.                     i += 3;
  125.                     break;
  126.                 }
  127.             }
  128.  
  129.             while ((gapFlag == 3) && (i < end))
  130.             {
  131.                 prsm += strInTrackList[i];
  132.                 if (strInTrackList[i] == ']')
  133.                 {
  134.                     if (prsm == "")
  135.                         year_of_execution = -1;
  136.                     else /*newTrack.year_of_execution = atoi(prsm); выдает ошибку,
  137.                          пришлось вставлять свой конвертер*/
  138.                         year_of_execution = YearConvertFromString(prsm);                   
  139.                 }
  140.  
  141.             }
  142.            
  143.             if (i == end)
  144.                 if (track_name == "")
  145.                 {
  146.                     track_name = performer;
  147.                     performer = "unknow";
  148.                 }              
  149.                 else
  150.                 {
  151.                     performer = "error";
  152.                     track_name = "error";
  153.                 }
  154.         }
  155.  
  156.         void showTrack()
  157.         {
  158.             cout << performer << " - " << track_name << " [";
  159.             if (year_of_execution != -1)
  160.                 cout << year_of_execution << "] ";
  161.             else
  162.                 cout << "unknow] ";
  163.         }
  164.  
  165.        
  166.     };
  167.     multimap <string, track> track_list;
  168.     //multimap <string, track> track_list;
  169.    
  170.  
  171.     void get_track_list_in_multimap()
  172.     {
  173.         string strTrack;
  174.         track test = track();      
  175.         ifstream in_track_list("track_list.txt");
  176.         while (in_track_list.peek() != EOF)
  177.         {
  178.             getline(in_track_list, strTrack);
  179.             test.getTrackFromString(strTrack);
  180.             track_list.insert(pair <string, track>(test.performer, test));
  181.         }
  182.        
  183.     }
  184.  
  185.     void show_track_list()
  186.     {
  187.         auto iterPair = track_list.equal_range("Edguy");
  188.         if (iterPair.first == iterPair.second)
  189.             cout << "Not found";
  190.         else
  191.         {
  192.             for (auto music_treck = iterPair.first; music_treck != iterPair.second; ++music_treck)
  193.             {
  194.                 music_treck->second.showTrack();
  195.                 cout << '\n';
  196.             }
  197.         }
  198.     }
  199.  
  200.  
  201.     /*
  202.         track getTrack(string strInTrackList, string way)
  203.         {
  204.             ifstream in_track_list(way);
  205.         }
  206.     */
  207.     // о пути к файлу   
  208.  
  209.     /*
  210.  
  211.     void get_track_list()
  212.     {
  213.         ifstream in_track_list("track_list.txt");
  214.     }*/
  215.         //мультимап
  216.  
  217. };
  218.  
  219. int main()
  220. {
  221.     Music_Player myPlayer;
  222.     myPlayer.get_track_list_in_multimap();
  223.     myPlayer.show_track_list();
  224.  
  225.    
  226.     //mciSendString("play D:\\Arch Enemy - Nemesis.mp3 wait", NULL, 0, NULL);
  227.  
  228.     //mciSendString("open \"D:\music2\my music\Arch Enemy - Nemesis.mp3\" type mpegvideo alias mp3", NULL, 0, NULL);
  229.  
  230.  
  231.  
  232.  
  233.  
  234.     //_getch();
  235.     return 0;
  236.  
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement