Hi. I have this assignment and have absolutely hit a wall here. I will give the assignment details, then say what the issue is:
Consider a collection of songs in an MP3 library where each song is characterized by artistName, songTitle, album, playTime (in seconds), musicCategory, and albumProducer – hence, you will need to use a struct data type. The musicCategory is represented by an enumeration type called SongCategory. The MP-3 library can hold a maximum of 200 songs at a time. The collection of songs is stored in a text file, which you will need to create with songs of your choice. You are free to select any format by which the songs are stored in the text file.
Write a program that reads the songs data from the text file, and stores it in an array of the struct data type, each of which represents a song in the library
- PrintAllRecords: Outputs to a text file all the contents of the MP3 library
- AddRecord: Adds a new record at the end of the MP3 library.
- DeleteRecord: Removes a specific record from the MP3 library, and then shifts the array accordingly.
- UpdateRecord: For a given song record, it updates one or more fields.
- SortRecords: Sorts all the records in the MP3 library according to the name of the song artist.
Now, I cannot for the life of me get the enum to work. It doesn't display correctly, either showing a LARGE number, or repeating the wrong value for each category.
Any help to ANY of the assignment is welcomed. Thanks ahead of time. :)
Here's my code so far:
#include<iostream>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;
/*enum songCategory {ROCK = 0, ALTERNATIVE = 1, CLASSICAL = 2, SOUNDTRACK= 3, CHILDREN=4, OTHER=5};*/
struct MyLibrary
{
string albumName;
string songName;
string artistName;
string playTime;
string genre;
string albumProducer;
};
void GetLibrary(ifstream& inFile, MyLibrary Library[]);
void PrintLibrary(ofstream& outFile, MyLibrary Library[]);
void PrintToScreen(MyLibrary Library[]);
void AddRecord(ofstream& outFile, MyLibrary Library[]);
const int MAX_SIZE = 200;
int main()
{
ifstream inFile;
ofstream outFile;
inFile.open("MySongLibrary.txt");
outFile.open("OrganizedLibrary.txt");
MyLibrary songInfo[MAX_SIZE];
GetLibrary(inFile, songInfo);
PrintLibrary(outFile, songInfo);
//PrintToScreen(songInfo);
AddRecord(outFile, songInfo);
inFile.close();
outFile.close();
return 0;
}
void GetLibrary(ifstream& inFile, MyLibrary Library[])
{
for(int i = 0; i < MAX_SIZE; i++)
{
string category;
getline(inFile, Library[i].albumName);
getline(inFile, Library[i].songName);
getline(inFile, Library[i].artistName);
getline(inFile, Library[i].playTime);
getline(inFile, Library[i].genre);
/*getline(inFile, category);
if(category == "ROCK")
Library[i].genre = ROCK;
else if(category == "ALTERNATIVE")
Library[i].genre = ALTERNATIVE;
else if(category == "CLASSICAL")
Library[i].genre = CLASSICAL;
else if(category == "SOUNDTRACK")
Library[i].genre = SOUNDTRACK;
else if(category == "CHILDREN")
Library[i].genre = CHILDREN;
else if(category == "OTHER")
Library[i].genre = OTHER;*/
getline(inFile, Library[i].albumProducer);
}
}
void PrintLibrary(ofstream& outFile, MyLibrary Library[])
{
for(int i = 0; i < MAX_SIZE; i++)
{
outFile << right << setw(3) << i + 1 << ") ";
outFile << Library[i].albumName << endl;
outFile << " " << Library[i].songName << endl;
outFile << " " << Library[i].artistName << endl;
outFile << " " << Library[i].playTime << endl;
outFile << " " << Library[i].genre << endl;
outFile << " " << Library[i].albumProducer << endl << endl;
}
}
void PrintToScreen(MyLibrary Library[])
{
for(int i = 9; i < MAX_SIZE; i++)
{
cout << right << setw(3) << i + 1 << ") ";
cout << Library[i].albumName << endl;
cout << " " << Library[i].songName << endl;
cout << " " << Library[i].artistName << endl;
cout << " " << Library[i].playTime << endl;
cout << " " << Library[i].genre << endl;
cout << " " << Library[i].albumProducer << endl << endl;
}
}
void AddRecord(ofstream& outFile, MyLibrary Library[])
{
cout << "Please enter the Album Name" << endl;
cin.getline(Library[i].albumName, albumName);
outFile << Library[i].albumName;
cout << "Please enter the Song Name" << endl;
cin >> Library[i].songName;
}