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

There is a file of Buddy Holly albums on the internet. Each entry has t Eollowin

ID: 3859542 • Letter: T

Question

There is a file of Buddy Holly albums on the internet. Each entry has t Eollowing form Name of album Year released from 1 to 12 names of songs (in cut number order) An album separator line is made up of equal signs Your assignment is: for each album: 1. read in the Album 2. Name, Year and songs Sort the songs alphabetically for all albums: 1. Sort the albums by Album Name alphabetically 2. Print the Album Name, Date, and the list of songs (alphabetically Some Sample Output : Buddy Holly 1958 10. Baby I Don't Care 7. Everyday 1. I'm Gonna Love You Too 4. Listen to Me 12. Little Baby 3. Look at Me 8. Mailman, Bring Me No More Blues 2. Peggy Sue 11 Rave On! 6. Ready Teddy 5. Valley of Tears 9. Words of Love Notes You will need to use the string operators and methods by C+ Here are a few (which you may, or may not, need for this assignment) provided #include string> /I determine the number of characters in a string st.size( orst.length) Isubstring search poe datastring.find("- / picking off a substring ssst.substr (start); ssst.substr(start, length) You may have problems with.. Input the albums are separated byso you have count there are a different number of songs on the albums, sort you will have to compare the song name (during the to check for equals and eof at the same time so you will need a count' field for each album sort) but you have to swap the name AND the cut nusber

Explanation / Answer

The following program reads an album properly from the file. You just need to add a while loop that keeps reading until eof. In the main, I just read two albums and tested if they were read properly. I used my own file albums.txt

#include <iostream>

#include <string>

#include <vector>

#include <fstream>

#include <cassert>

using namespace std;

struct Album

{

string name;

int year;

vector<string> songs;

};

Album * read_album(ifstream &);

int main()

{

ifstream f1("albums.txt");

Album *a1 = read_album(f1);

assert(a1->name == "album1");

cout << ".";

Album *a2 = read_album(f1);

assert(a2->name == "album2");

cout << ".";

cout << endl;

return 0;

}

Album * read_album(ifstream &in_file)

{

char sample{};

string song_name{};

Album *a1 = new Album;

in_file >> a1->name;

in_file >> a1->year;

while ( !in_file.eof() )

{

in_file >> song_name;

// we read a line '====...'

if (song_name.find('=') == 0)

{

return a1;

}

a1->songs.push_back(song_name);

}

// if its the last album then we will never see '='

return a1;

}

albums.txt

====

album1
2017
1. a song 1
2. x song 2
=================
album2
2017
1. z song 1
2. a song 2
3. g song 3

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