Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#include #include #include #include #include using namespace std; enum Genre { ROCK, POP, HIP _ HOP, JAZZ, CLASSICAL } ; struct Track { string name;
#include
#include
#include
#include
#include
using namespace std;
enum Genre
ROCK,
POP,
HIPHOP,
JAZZ,
CLASSICAL
;
struct Track
string name;
string fileLocation;
;
struct Album
string artistName;
string albumName;
Genre genre;
int numTracks;
Track tracks;
;
const int MAXALBUMS ;
Album albumsMAXALBUMS;
int numAlbums ;
void readAlbumsFromFileconst string& fileName
ifstream inputFilefileName;
if inputFile
cout "Error opening the file.
;
exitEXITFAILURE;
int numAlbumsInFile;
inputFile numAlbumsInFile;
for int albumIndex ; albumIndex numAlbumsInFile; albumIndex
Album& currentAlbum albumsnumAlbums;
inputFile.ignore; Consume the newline character after the previous number
getlineinputFile currentAlbum.artistName;
getlineinputFile currentAlbum.albumName;
int genre;
inputFile genre;
currentAlbum.genre staticcastgenre;
inputFile currentAlbum.numTracks;
for int trackIndex ; trackIndex currentAlbum.numTracks; trackIndex
inputFile.ignore; Consume the newline character after the previous number
getlineinputFile currentAlbum.trackstrackIndexname;
getlineinputFile currentAlbum.trackstrackIndexfileLocation;
numAlbums;
if numAlbums MAXALBUMS
cout "Maximum number of albums reached.
;
break;
inputFile.close;
bool compareAlbumsByGenreconst Album& a const Album& b
return agenre bgenre;
void displayAllAlbums
if numAlbums
for int i ; i numAlbums; i
cout "Album i :
;
cout "Artist: albumsiartistName
;
cout "Album: albumsialbumName
;
cout "Genre: albumsigenre
;
cout "Tracks:
;
for int j ; j albumsinumTracks; j
cout albumsitracksjname albumsitracksjfileLocation
;
else
cout No albums available.
;
void displayAlbumByGenre
vector sortedAlbumsalbums albums numAlbums;
sortsortedAlbumsbegin sortedAlbums.end compareAlbumsByGenre;
for const Album& currentAlbum : sortedAlbums
cout "Artist: currentAlbum.artistName
;
cout "Album: currentAlbum.albumName
;
cout "Genre: currentAlbum.genre
;
cout "Tracks:
;
for int j ; j currentAlbum.numTracks; j
cout currentAlbum.tracksjname currentAlbum.tracksjfileLocation
;
cout
;
void displayAlbum
int displayOption;
cout "Choose display option:
;
cout Display all albums
;
cout Display albums sorted by genre
;
cout "Enter your choice: ;
cin displayOption;
switch displayOption
case :
displayAllAlbums;
break;
case :
displayAlbumByGenre;
break;
default:
cout "Invalid choice. Displaying all albums by default.
;
displayAllAlbums;
break;
void updateAlbum
if numAlbums
int albumIndex;
cout "Enter the index of the album to update: ;
cin albumIndex;
if albumIndex && albumIndex numAlbums
int updateOption;
cout "Choose update option:
;
cout Update album name
;
cout Update album genre
;
cout "Enter your choice: ;
cin updateOption;
switch updateOption
case :
cout "Enter the new album name: ;
cin.ignore; Consume the newline character left by previous cin
getlinecin albumsalbumIndexalbumName;
cout "Album name updated successfully.
;
break;
case :
cout "Enter the new genre ROCK, POP, HIPHOP, JAZZ, CLASSICAL: ;
int genre;
cin genre;
albumsalbumIndexgenre staticcastgenre;
cout "Album genre updated successfully.
;
break;
default:
cout "Invalid up
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started