Problem Statement: 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 the problem and i Have that

so can you please help me finish this?

// prototype
// <data type>& indentifer
// definition
// <data type>& identifier 

// File name:
// Program description:
// Author:
// Last modified:

#include <iostream>
#include <string>
#include <fstream>

using namespace std ;

// global user-defined type declaration
struct Song
{
	string artistName ;
	string songTitle ;
	string albumName ;
	int playTime ;
	string musicCategory ;
	string albumProducer ;
} ;

// named constants
const int MAX_SONGS = 200 ;

// function prototypes
void ReadSongs(ifstream&, Song[]) ;
void PrintAllRecords(const Song[]) ;
void AddRecord (ifstream&, Song[]);
void PrintToScreen(Song[]);


int main()
{
	Song mySongs[MAX_SONGS] ;	// array holding music library
	
	// open input file stream
	ifstream myInput;
	myInput.open("musiclist.txt");

	// populate music libray
	ReadSongs(myInput, mySongs) ;

	// print all records in library
	PrintAllRecords(mySongs) ;

	PrintToScreen(mySongs);

	// Add Records in library
	AddRecord (myInput, mySongs);


	return 0 ;
}

// Function name:
// Function description:
// Pre-condition:
// Post-condition:
void ReadSongs(ifstream& myInput,	// OUT: input file stream
			   Song mySongs[])		// OUT: array of music library
{
	for(int i = 0; i < MAX_SONGS; i++)
	{
		getline(myInput, mySongs[i].artistName) ;
		getline(myInput, mySongs[i].songTitle) ;
		getline(myInput, mySongs[i].albumName) ;
		myInput >> mySongs[i].playTime ;
		myInput.ignore(100, '\n') ;		// consumes newline character
		getline(myInput, mySongs[i].musicCategory) ;
		getline(myInput, mySongs[i].albumProducer) ;
		myInput.ignore(100, '\n') ;		// consumes blank line
	}
	return ;
}

// Function name:
// Function description:
// Pre-condition:
// Post-condition:
void PrintAllRecords(const Song mySongs[])	// IN: input file stream
{
	ofstream myOutput ;
	myOutput.open("allRecordsPrint.txt") ;

	for (int i = 0; i < MAX_SONGS; i++)
	{
		myOutput << mySongs[i].artistName << endl ;
		myOutput << mySongs[i].songTitle << endl  ;
		myOutput << mySongs[i].albumName << endl  ;
		myOutput << mySongs[i].playTime << endl ;
		myOutput << mySongs[i].musicCategory << endl ;
		myOutput << mySongs[i].albumProducer << endl ;
		myOutput << endl ;
	}
	return ;
}


void PrintToScreen(Song mySongs[])

{

for(int i = 0; i < MAX_SONGS; i++)

{

	cout << right << setw(3) << i + 1 << ") ";
	cout << mySongs[i].albumName << endl;
	cout << " " << mySongs[i].songTitle << endl;
	cout << " " << mySongs[i].artistName << endl;
	cout << " " << mySongs[i].playTime << endl;
	cout << " " << mySongs[i].musicCategory << endl;
	cout << " " << mySongs[i].albumProducer << endl << endl;

}

}
void AddRecord (ofstream& myOutput, Song mySongs[])
{
	cout << "please enter the album name" << endl;
	for (int i = 0; i < MAX_SONGS; i++)
	{
		myOutput << mySongs[i].albumName;}
	
}

void DeleteRecord (

this far. can someone help me finish this?

Recommended Answers

All 4 Replies

This isn't a snippet, it's a homework assignment.

How do you think DeleteRecord() should work?

Deleting a record is fairly simple, all you need to do is create a temporary array and then just copy each value one by one, skipping the element you need to delete and then just copy the temp array to the main array.

Alternatively just make the element you need to delete 0.

Deleting a record is fairly simple, all you need to do is create a temporary array and then just copy each value one by one, skipping the element you need to delete and then just copy the temp array to the main array.

Alternatively just make the element you need to delete 0.

Setting to (0) won't work, the writeup clearly states that a shift is required.

Deleting a record is fairly simple, all you need to do is create a temporary array and then just copy each value one by one, skipping the element you need to delete and then just copy the temp array to the main array.

Alternatively just make the element you need to delete 0.

is there anything wrong with it?

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.