Answered step by step
Verified Expert Solution
Link Copied!

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,
HIP_HOP,
JAZZ,
CLASSICAL
};
struct Track {
string name;
string fileLocation;
};
struct Album {
string artistName;
string albumName;
Genre genre;
int numTracks;
Track tracks[10];
};
const int MAX_ALBUMS =5;
Album albums[MAX_ALBUMS];
int numAlbums =0;
void readAlbumsFromFile(const string& fileName){
ifstream inputFile(fileName);
if (!inputFile){
cout << "Error opening the file.
";
exit(EXIT_FAILURE);
}
int numAlbumsInFile;
inputFile >> numAlbumsInFile;
for (int albumIndex =0; albumIndex < numAlbumsInFile; ++albumIndex){
Album& currentAlbum = albums[numAlbums];
inputFile.ignore(); // Consume the newline character after the previous number
getline(inputFile, currentAlbum.artistName);
getline(inputFile, currentAlbum.albumName);
int genre;
inputFile >> genre;
currentAlbum.genre = static_cast(genre);
inputFile >> currentAlbum.numTracks;
for (int trackIndex =0; trackIndex < currentAlbum.numTracks; ++trackIndex){
inputFile.ignore(); // Consume the newline character after the previous number
getline(inputFile, currentAlbum.tracks[trackIndex].name);
getline(inputFile, currentAlbum.tracks[trackIndex].fileLocation);
}
numAlbums++;
if (numAlbums >= MAX_ALBUMS){
cout << "Maximum number of albums reached.
";
break;
}
}
inputFile.close();
}
bool compareAlbumsByGenre(const Album& a, const Album& b){
return a.genre < b.genre;
}
void displayAllAlbums(){
if (numAlbums >0){
for (int i =0; i < numAlbums; ++i){
cout << "Album "<< i +1<<":
";
cout << "Artist: "<< albums[i].artistName <<"
";
cout << "Album: "<< albums[i].albumName <<"
";
cout << "Genre: "<< albums[i].genre <<"
";
cout << "Tracks:
";
for (int j =0; j < albums[i].numTracks; ++j){
cout <<""<< albums[i].tracks[j].name <<"-"<< albums[i].tracks[j].fileLocation <<"
";
}
}
} else {
cout <<"No albums available.
";
}
}
void displayAlbumByGenre(){
vector sortedAlbums(albums, albums + numAlbums);
sort(sortedAlbums.begin(), 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 =0; j < currentAlbum.numTracks; ++j){
cout <<""<< currentAlbum.tracks[j].name <<"-"<< currentAlbum.tracks[j].fileLocation <<"
";
}
cout <<"
";
}
}
void displayAlbum(){
int displayOption;
cout << "Choose display option:
";
cout <<"1. Display all albums
";
cout <<"2. Display albums sorted by genre
";
cout << "Enter your choice: ";
cin >> displayOption;
switch (displayOption){
case 1:
displayAllAlbums();
break;
case 2:
displayAlbumByGenre();
break;
default:
cout << "Invalid choice. Displaying all albums by default.
";
displayAllAlbums();
break;
}
}
void updateAlbum(){
if (numAlbums >0){
int albumIndex;
cout << "Enter the index of the album to update: ";
cin >> albumIndex;
if (albumIndex >=0 && albumIndex < numAlbums){
int updateOption;
cout << "Choose update option:
";
cout <<"1. Update album name
";
cout <<"2. Update album genre
";
cout << "Enter your choice: ";
cin >> updateOption;
switch (updateOption){
case 1:
cout << "Enter the new album name: ";
cin.ignore(); // Consume the newline character left by previous cin
getline(cin, albums[albumIndex].albumName);
cout << "Album name updated successfully.
";
break;
case 2:
cout << "Enter the new genre (0-ROCK, 1-POP, 2-HIP_HOP, 3-JAZZ, 4-CLASSICAL): ";
int genre;
cin >> genre;
albums[albumIndex].genre = static_cast(genre);
cout << "Album genre updated successfully.
";
break;
default:
cout << "Invalid up

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

When is Equation (2.46) valid?

Answered: 1 week ago

Question

Compare the different types of employee separation actions.

Answered: 1 week ago

Question

Assess alternative dispute resolution methods.

Answered: 1 week ago

Question

Distinguish between intrinsic and extrinsic rewards.

Answered: 1 week ago