QuestionQuestion

Transcribed TextTranscribed Text

Compile your program as follows: g++ -o lib_info lib_info.cpp In this lab, you will be working on a file that contains information about MP3 files. An example is in the file Music.txt. 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: 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. Title Time (m:ss) Artist Album Genre Track For example, here are the first ten lines of Music.txt : Back_In_Black 4:15 AC_DC Back_In_Black Rock 6 Larks'_Tongues_In_Aspic,_Part_III 5:56 King_Crimson Three_of_a_Perfect_Pair Rock 9 Ravel,_Menuet_Antique 5:28 Casadesus,_Robert Ravel,_Complete_Piano_Music,_Disc_2 Classical 8 Pungee 3:02 Meters,_The Look-Ka_Py_Py Rock 3 Naima 4:24 Coltrane,_John Giant_Steps Jazz 6 Rachmaninoff,_Piano_Concerto_#3_in_Dm,_Opus_30,_2._Intermezzo_-_Adagio 11:43 Berman,_Lazar Rachmaninoff_-_Piano_Concerto_#3 Classical 2 Grieg,_Norwegian_Melodie,_EG_108,_#44,_Sailor's_Song_-_Hurrah_For_Jonas_Anton_Hjelm 0:32 Steen-Nokleberg,_Einar Grieg_Piano_Music,_Volume_05 Class Beethoven,_Sonata_#12_in_Ab,_Opus_26,_2._Scherzo._Allegro_molto 2:51 Richter,_Sviatoslav Russian_Piano_School,_V06 Classical 9 Your_Cheatin'_Heart 2:44 Armstrong,_Louis Highlights_From_His_Decca_Years,_Disc_2 Jazz 11 Pieces_Of_Dreams 5:19 Turrentine,_Stanley More_Than_A_Mood Jazz 6 And here's a small file for testing, S Small.txt : Countdown 2:25 Coltrane,_John Giant_Steps Jazz 3 Down_In_Brazil 6:07 Walton,_Cedar Naima Jazz 4 Giant_Steps 4:02 Puente,_Tito El_Rey Jazz 5 Giant_Steps 4:46 Coltrane,_John Giant_Steps Jazz 1 Mr._P.C. 7:02 Coltrane,_John Giant_Steps Jazz 7 Naima 4:24 Coltrane,_John Giant_Steps Jazz 6 Naima 5:16 Lyle,_Bobby Night_Breeze Jazz 5 Naima 5:36 Tjader,_Cal A_Fuego_Vivo Jazz 6 Naima 7:49 Walton,_Cedar Naima Jazz 6 Naima 8:38 Walton,_Cedar Eastern_Rebellion Jazz 2 This_Guy's_In_Love_With_You 8:10 Walton,_Cedar Naima Jazz 2 Here it is on Small.txt: UNIX> lib_info Small.txt Coltrane, John: 4, 18:37 Giant Steps: 4, 18:37 1. Giant Steps: 4:46 3. Countdown: 2:25 6. Naima: 4:24 7. Mr. P.C.: 7:02Lyle, Bobby: 1, 5:16 Night Breeze: 1, 5:16 5. Naima: 5:16 Puente, Tito: 1, 4:02 El Rey: 1, 4:02 5. Giant Steps: 4:02 Tjader, Cal: 1, 5:36 A Fuego Vivo: 1, 5:36 6. Naima: 5:36 Walton, Cedar: 4, 30:44 Eastern Rebellion: 1, 8:38 2. Naima: 8:38 Naima: 3, 22:06 2. This Guy's In Love With You: 8:10 4. Down In Brazil: 6:07 6. Naima: 7:49 UNIX>

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

#include <sstream>
#include <map>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <string>
using namespace std;

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;
};


// Converts the string in m:ss format to seconds
int Time2Int(string s)
{
int min, sec;
sscanf(s.c_str(), "%d:%d\n", &min, &sec);
return min * 60 + sec;
}


// Converts seconds into string representing time in m:ss format
string Int2Time(int time)
{
ostringstream m, s;
string str;
m << time / 60;
s << time % 60;
str = s.str();
if (str.length() == 1) // adding leading zero if seconds < 10
{
str = "0" + str;
}
return m.str() + ":" + str;
}...
$10.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Data Structures and Algorithms Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats