Consider a collection of songs in an MP-3 library where each song is characterized by artistName, songTitle, albumName, playTime (in seconds), musicCategory, and albumProducer – hence, you will need to use a struct data type to hold a song and an array of structs to hold the song collection. 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.

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. The program should facilitate the following functionality, where each should be implemented as a separate C++ function.
1. PrintAllRecords: Outputs to a text file all the contents of the MP-3 library
2. AddRecord: Adds a new record at the end of the MP-3 library.
3. DeleteRecord: Removes a specific record from the MP-3 library, and then shifts the array accordingly. This will involve searching for the song record that needs to be deleted.

This is homework and I have this much so far. Can someone find any problem or finish? because I am stuck and I have no clue how to addRecord or DeleteRecord.

#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 Name" << endl;
		cin >> Library[i].songName;
}

People are not going to do your homework for you. Please figure out a concise statement of a problem you are having and you'll get a lot more help here.

Dave

okay here is my problem. I get the question but for addrecord and delete record i don't exactly understand what I need to do.

Add Record:
Go to the end of the file.
Add in a new record with the same format.

Delete Record:
You could read in all the data,
then omit the element that has to be deleted
And Write back all the data.
Just be sure that you dont open the file in ios::ate or ios::app mode.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.