should read in from a file called library.txt the specifics of 25 songs – the name of the
song, the artist of the song, the album the song comes from, the minutes and seconds of
the song. At the beginning of your program, the songs should be printed out in the order
in which they were read from the file (unsorted).
You are to present the following options for sorting the songs – by song name, artist
name, album name, or time. You will need to allow the user to choose to sort in
ascending or descending order.
Additionally, you will need to allow for searching. Allow the user to type in the name of
a song, artist, or album. If there is a match, print out the songs that match the criteria. If
there is no match, print out a message to that effect. You may not use any predefined
libraries or functions for searching or sorting.
Requirements:
You must use a class called myTunes. This class has five data attributes – song name,
artist name, album title, minutes, and seconds. You must have getters and setters that
address these.
Other methods for this class (at minimum): display – prints out a track, in order of song
name, artist name, album name, and time (mm:ss); and assign – takes the contents of an
object of myTunes and assigns it to the object calling assign.
Outside of the class definition, you’ll need functions to address the following: searching,
sorting, reading data from the file, menu, and printing of tracks. You may find writing a
swap function particularly useful, too.
You’ll need some kind of array to handle the data (hint: an array of myTunes objects,
maybe?).
Other tips:
Look at the way the data is formatted in the file and look at how it appears in the sample
screenshots. You’ll have to figure out how to address changing the data in places, after
you’ve read it in.
You may find the cin.ignore command useful in certain places.
// Viers, Ethan
// April 12, 2011
//assignment 10
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
using std::getline;
using std::setw;
int menuoption;
class myTunes{
public:
myTunes(string n, string art, string alb, int mm, int ss){
setSongName(n);
setSongArtist(art);
setSongAlbum(alb);
setSongMinutes(mm);
setSongSeconds(ss);
}
void setSongName(string n){
SongName = n;
}
void setSongArtist(string art){
SongArtist = art;
}
void setSongAlbum(string alb){
SongAlbum = alb;
}
void setSongMinutes(int mm){
SongMinutes = mm;
}
void setSongSeconds(int ss){
SongSeconds = ss;
}
string getSongName(){
return SongName;
}
string getSongArtist(){
return SongArtist;
}
string getSongAlbum(){
return SongAlbum;
}
int getMinutes(){
return SongMinutes;
}
int getSeconds(){
return SongSeconds;
}
private:
string SongName, SongArtist, SongAlbum;
int SongMinutes, SongSeconds;
};
int menu(){
cout<<"1) Song Name"<<endl;
cout<<"2) Artist Name"<<endl;
cout<<"3) Album Name"<<endl;
cout<<"4) Track Time"<<endl;
cout<<"5) Search for a song name" <<endl;
cout<<"6) Search for an artist name"<<endl;
cout<<"7) Search for an album name"<<endl;
cout<<"8) Quit"<<endl;
cin >> menuoption;
}
int main()
{
ifstream inFile;
inFile.open("library1.txt");
string songname, songartist, songalbum;
int songminutes, songseconds;
int counter = 0;
char letter;
int text[25];
string myTunes[25];
string insert;
int input;
while(getline(inFile, songname))
{
myTunes[counter] = songname;
songartist = songname.substr( songname.find(" ")+1, songname.length()-1 );
letter = songartist;
input = letter;
text[counter] = input;
counter++;
}
for (int count = 0; count < 25; count++)
inFile >> myTunes[count];
for (int count = 0; count < 25; count++)
cout << setw(18) << myTunes[count] << endl;
inFile.close();// close the text file (names2.txt)
system("PAUSE");
return 0;
}

New Topic/Question
Reply




MultiQuote






|