Hi folks i've been working hard with an assignment for college but have become stuck. Hoping u kind guys could give me some pointers. The assignment section reads:
MP3 Player
As stated above, this section of the player will not be loading and actually playing a
genuine MP3 file, it will handle a simple simulation.
Contain a minimum of five —“MP3 files” though be able to contain an unlimited number.
Select next M P3.
Select previous M P3.
Show name, current position and length of M P3.
e.g. Bob Dylan Hurricane 12/52
Step forward by one position unit. Moving to next if at end.
Step forward by ten position units. Not passing end.
Step backwards by ten position units.
Not passing start.
When select next or previous M P3 the system should automatically wrap around both ways so that it will step from the fifth to the first when selecting —next“ or — step forward“ or from the fifth to the first when selecting —previous“.
You should choose your own titles for the MP3 files.
The details of each —MP3 file should be contained within and loaded from a suitable text file that is accessed by you application and readable using a suitable text editor such as Notepad™ .
Loading is only permitted when the overall system starts, not when switching to this player.
The system should automatically save the loaded / stored M P3 files at termination overall application not when switching away from this player.
So to sum it up its a console application that reads information from a text file containg information on MP3's. So far i've written the class:
class MP3
{
char * songtitle;
char * artiste;
int tracklength;
public:
MP3(char *, char *, int);
~MP3::MP3();
const char * getartiste () const(return artiste;)
const char * getsongtitle () const(return songtitle;)
int tracklength const (return tracklength;)
MP3::~MP3()
{
delete artiste;
delete songtitle;
}
};
MP3::MP3(char * newartiste, char * newsongtitle, int newtracklength)
{
artiste = newartiste;
tracklength = newtracklength;
songtitle = newsongtitle;
}
Ive also worked out the loop to create the array of MP3's:
mp3 *arMP3[5]; //Create an array of pointers to 5 mp3 objects
for (nCount=0;ncount<5;nCount++)
arMP3[nCount] = new mp3;
But i'm struggling to work out how to write data from a text file into the 5 MP3's of the array. I know how to read information from a file into a simple array using this code:
ifstream myfile ("example.txt"); //opening the file.
if (myfile.is_open()) //if the file is open
{
while (! myfile.eof() ) //while the end of file is NOT reached
{
getline (myfile,line); //get one line from the file
array[loop] = line;
cout << array[loop] << endl; //and output it
loop++;
}
myfile.close(); //closing the file
}
But i'm not sure how to write data from this file into the MP3 objects. Any help would be muchly appreciated. Thanks