1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
struct musicRecord
{
string name, album, artist, genre;
};
void addTrack(musicRecord list[], int &size)
{
musicRecord tmp;
char save;
while (size < MAX_SIZE)
{
system("cls");
cout << "*Type 'quit' to exit on any entry.*" << endl << endl;
cout << "Enter the name of the song: ";
getline(cin, tmp.name);
if ( strcmp(tmp.name.c_str(), "quit") ==0)
{
system("cls");
break;
}
cout << "Track:\t";
cout << tmp.name << endl << endl;
cout << "What album is the song in: ";
getline(cin, tmp.album);
if ( strcmp(tmp.album.c_str(), "quit") == 0)
{
system("cls");
break;
}
cout << "Album:\t" ;
cout << tmp.album << endl << endl;
cout << "The artist of the song: ";
getline(cin, tmp.artist);
if ( strcmp(tmp.artist.c_str(), "quit") == 0)
{
system("cls");
break;
}
cout << "Artist:\t";
cout << tmp.artist << endl << endl;
cout << "The song's genre: ";
getline(cin, tmp.genre);
if ( strcmp(genre, "quit") ==0)
{
system("cls");
break;
}
cout << "Genre:\t";
cout << tmp.genre << endl << endl;
cout << "Do you want to store these records? (y/n)" << endl;
cin >> save;
cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
if( (save | 32) == 'y')
{
list[++size] = tmp;
}
}
}
void bubbleSort(musicRecord list[], int size)
{
for (int i=0; i<size; i++)
{
for (int j=0; j < size-i; j++)
{
if (strcmp(list[j].name.c_str(),list[j+1].name.c_str()) > 0)
{
swap(list[j], list[j + 1]);
}
}
}
}
void displayTracks(const musicRecord list[], int size)
{
if (size < 1) {
system("cls");
cout << "There are no records to display!" << endl;
}
else {
system("cls");
cout << "These are the songs found in the file: \n" << endl;
for(int i = 0; i < size; i++) {
cout << "Title: " << list[i].name << endl;
cout << "Album: " << list[i].album << endl;
cout << "Artist: " << list[i].artist << endl;
cout << "Genre: " << list[i].genre << endl;
}
system("pause");
system("cls");
}
}
void openData(musicRecord list[], int &size)
{
system("cls");
ifstream doc("Tracks.txt");
string str;
stringstream strstrm;
size = 0;
if (!doc.fail())
{
while(!doc.eof() && size < MAX_SIZE)
{
getline(doc, str, ';');
strstrm.str(""); strstrm.clear();
strstrm << str;
list[size].name = str;
getline(doc, str, ';');
strstrm.str(""); strstrm.clear();
strstrm << str;
strstrm >> list[size].artist;
getline(doc, str, ';');
strstrm.str(""); strstrm.clear();
strstrm << str;
strstrm >> list[size].album;
getline(doc, str, ';');
strstrm.str(""); strstrm.clear();
strstrm << str;
strstrm >> list[size].genre;
++size;
}
cout << endl << size << " records were loaded into the program." << endl;
system("PAUSE");
}
else
{
cout << "ERROR: problem with file" << endl;
system("PAUSE");
system("cls");
}
}
void saveData(const musicRecord list[], int size)
{
//remove("Tracks.txt");
ofstream outfi("Tracks.txt");
if (!outfi.fail())
{
cout << "The tracks are being added to the list! \n";
for(int i = 0; i < size; i++)
{
outfi << list[i].name << ";";
outfi << list[i].album << ";";
outfi << list[i].artist << ";";
outfi << list[i].genre << ";\n";
}
cout << endl << size << " tracks have been saved to the file. \n" << endl;
outfi.close();
system("PAUSE");
}
else
{
cout << "ERROR: cannot save to file!" << endl;
system("PAUSE");
}
system("cls");
}
|