Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this lab, you will be working on a file that contains information about MP3 f

ID: 3628205 • Letter: I

Question

In this lab, you will be working on a file that contains information about MP3 files.It is in a very specific format. Each line of standard input contains exactly six words that describe a song that is in my MP3 library:

Title Time (m:ss) Artist Album Genre Track
None of the words have spaces -- where there should be a space, there is instead an underscore.

Your job is to write the program lib_info.cpp, which will be called with a single command line argument:

lib_info file

The argument file is a file in the format of Music.txt. You do not have to error-check this file. You may assume that it is in the correct format, and that no combination of artist/album has songs with the same track number.

The first thing your program is going to do is read in all the information and turn all underscores back into spaces.

Next, lib_info is going to print out all of MP3 files in the following format: For each artist (sorted lexicographically), the program will print out the artist name, followed by a colon and space, then the number of songs that have that artist's name, followed by a comma and a space, and then the total time of all songs that have that artist's name.

After each artist, you will print out each album by that artist, sorted lexicographically (and indented by eight spaces), followed again by the number of songs and total time for that album.

After each album, you will print out the title of each song on that album, sorted by track number. The format of each of these lines will be 16 spaces, the track number, a period, a space, the song's name, a colon, a space and the song's time.
examples of input can be downloaded from here http://alicex.narod.ru/Lab1.zip
The output should look like this

Things that must be used:

1. Maps

2. This classes

class Song {
public:
string title;
int time;
int track;
};

class Album {
public:
map <int, Song *> songs;
string name;
int time;
};

class Artist {
public:
map <string, Album *> albums;
string name;
int time;
int nsongs;
};

3. Program should be able to hold unlimited amount of songs, albums and artists.

Explanation / Answer

#include <iostream>
#include <fstream>
#include<iomanip>
#include <string>
using namespace std;

struct Album
{string artist;
string album;
int num_songs;
string songs[10];
int minutes[10];
int seconds[10];
int track[10];
string type[10];
int tot_minutes;
int tot_seconds;

};
int getinfo(Album[],ifstream& );
void newalbum(Album[],string,string,string,string,int,int,int,int&);
void oldalbum(Album[],string,string,int,int,int,int);
void sort(Album[],int);
void print(Album[],int);
int search(Album[],string,int);
string remove(string);
void swap(string&,string&);
void swap(int&,int&);

int main(int argc, char * argv[])
{Album a[100];
int i=0;
ifstream in;
in.open(argv[1]);
if(in.fail())
   { cout<<"file did not open please check it ";
     return 1;
    }
i=getinfo(a,in);
sort(a,i);
print(a,i);
in.close();
return 0;
}
void swap(string& a,string& b)
{string t;
t=a;
a=b;
b=t;
}
void swap(int& a,int& b)
{int t;
t=a;
a=b;
b=t;
}
void sort(Album a[],int i)
{int j,k;
Album temps;
for(j=0;j<i-1;j++)
        for(k=j;k<i;k++)
            if(a[j].artist>a[k].artist)
                {temps=a[k];
                a[k]=a[j];
                a[j]=temps;
                }
}

void print(Album a[],int n)
{int i,j,k;
for(j=0;j<n;j++)  
{cout<<a[j].artist<<": "<<a[j].num_songs<<", "<<a[j].tot_minutes<<":"<<
        setw(2)<<setfill('0')<<a[j].tot_seconds<<" ";
cout<<setw(8)<<setfill(' ')<<" "<<a[j].album<<": "<<a[j].num_songs<<", "<<a[j].tot_minutes<<":"<<
        setw(2)<<setfill('0')<<a[j].tot_seconds<<" ";

for(i=0;i<a[j].num_songs-1;i++)
        for(k=i;k<a[j].num_songs;k++)
             if(a[j].track[i]>a[j].track[k])
                  {swap(a[j].track[i],a[j].track[k]);
                   swap(a[j].minutes[i],a[j].minutes[k]);
                   swap(a[j].seconds[i],a[j].seconds[k]);
                   swap(a[j].type[i],a[j].type[k]);
                   swap(a[j].songs[i],a[j].songs[k]);
                   }
    for(i=0;i<a[j].num_songs;i++)
           cout<<setw(16)<<setfill(' ')<<" "<<setw(2)<<right<<a[j].track[i]<<"."
                <<" "<<a[j].minutes[i]<<":"<<setw(2)<<setfill('0')
                 <<a[j].seconds[i]<<" ";
//cout<< ";   
                      }
}
string remove(string s)
{int k;
    for(k=0;k<s.length();k++)
            if(s[k]=='_')
                 s[k]=' ';
return s;  
}
int getinfo(Album a[],ifstream &in)
{string name,artist,album,type,t;
int min,sec,track,temp;
string input;
int i=0,n,m,k;
getline(in,input);
while(in)
      {//cout<<input<<endl;
      n=0;
      m=input.find(' ',n);
       name=input.substr(n,m-n);     
       name=remove(name);
                
       n=m+1;
       m=input.find(':',n);
       t=input.substr(n,m-n);
        min=atoi(t.c_str());
        n=m+1;
       m=input.find(' ',n);
       t=input.substr(n,m-n);
       sec=atoi(t.c_str());
       //cout<<min<<" * "<<sec<<endl;
       n=m+1;
       m=input.find(' ',n);     
      artist=input.substr(n,m-n);
      artist=remove(artist);
      n=m+1;
       m=input.find(' ',n);
      album=input.substr(n,m-n);
       album=remove(album);
      n=m+1;
       m=input.find(' ',n);
      type=input.substr(n,m-n);
      n=m+1;
       m=input.find(' ',n);
      track=atoi(input.substr(n,m-n).c_str());
      k=search(a,album,i);
     // cout<<k;
      if(k<0)
          newalbum(a,album,name,artist,type,min,sec,track,i);
         
      else
          oldalbum(a,name,type,min,sec,track,k);
/* if(sec==47)        
     cout<<a[i-1].artist<<" "<<a[i-1].album<<" "<<a[i-1].num_songs<<" ";
   
for(int p=0;p<a[0].num_songs;p++)
    cout<<a[0].minutes[p]<<" "<<a[0].seconds[p]<<" "<<a[0].track[p]<<
    " "<<a[0].type[p]<<" ";
cout<<a[0].tot_minutes<<" "<<a[0].tot_seconds<<" "; */
      getline(in,input);
      }
//cout<<i<<endl;
return i;
}
int search(Album a[],string album,int n)
{int i;
for(i=0;i<n;i++)
    if(album.compare(a[i].album)==0)
         return i;
return -1;
}
void newalbum(Album a[],string album,string name,string artist,
              string type,int min,int sec,int track,int &i)
{
a[i].artist=artist;
a[i].album=album;
a[i].num_songs=0;
a[i].tot_minutes=0;
a[i].tot_seconds=0;
oldalbum(a,name,type,min,sec,track,i);
i++;

}

void oldalbum(Album a[],string name,string type,int min,int sec,int track,int i)
{
a[i].songs[a[i].num_songs]=name;
a[i].minutes[a[i].num_songs]=min;
a[i].seconds[a[i].num_songs]=sec;   
a[i].songs[a[i].num_songs]=name;
a[i].track[a[i].num_songs]=track;
a[i].type[a[i].num_songs]=type;

a[i].tot_minutes+=min;
a[i].tot_seconds+=sec;

a[i].num_songs++;


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote