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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
|
#include <iostream>
#include <fstream>
#include <iomanip>
#include "library.h"
using namespace std;
//Function prototypes
char displayMenu();
void displayLibrary(Config &c);
void addAlbum(Config &c);
void searchLibrary(Config &c);
int main()
{
char choice;
bool notValid = true;
bool notDone = true;
Config config;
cout << "Album Count: " << config.albumCount << endl;
cout << "Artist Count: " << config.artistCount << endl;
cout << "Album-Artist Intersection Count: " << config.B_A_IntCount << endl;
do
{
choice = displayMenu();
switch (toupper(choice))
{
case 'A':
displayLibrary(config);
break;
case 'B':
//cout << "You Chose 'B'!" << endl;
break;
case 'C': //Add album option
addAlbum(config);
break;
/*case 'D': Don't need since artist is added with album...
cout << "You Chose 'D'!" << endl;
break; */
case 'X':
cout << "Thank you for playing\nGoodbye!" << endl;
notDone = false;
break;
default:
cout << "Choice was not A, B, C, or X \nPlease try again..." << endl;
}
} while(notDone); // could also be while(choice != 'X' && choice !='x')
return 0;
}
char displayMenu()
{
char menuChoice;
cout << "Enter the letter for the menu option you want:" << endl;
cout << "A. Display Library" << endl;
cout << "B. Search Library" << endl;
cout << "C. Add Album" << endl;
//cout << "D. Add Artist" << endl; No longer need, since we're adding artist along with album...
cout << "X. Quit Program" << endl;
cin >> menuChoice;
cin.ignore(256, 10); //ignore up to 256 "Extra" characters or until "\n"
//cin.ignore();
return menuChoice;
}
void displayLibrary(Config &c)
{
ifstream inputFile;
string temp;
int artistDisplayed = 0;
Album albums[c.albumCount];
Artist artists[c.artistCount];
A_B_Int abint[c.B_A_IntCount];
// Read in albums:
/* int albumID;
string albumName;
int releaseDate;
*/
inputFile.open(c.albumFileName);
if (!inputFile)
{
cout << "Error opening album file." << endl;
}
else
{
for (int i = 0; i < c.albumCount; i++)
{
getline(inputFile, temp);
albums[i].albumID = stoi(temp);
getline(inputFile, temp);
albums[i].albumName = temp;
getline(inputFile, temp);
albums[i].releaseDate = stoi(temp);
getline(inputFile, temp);
albums[i].numArtists = stoi(temp);
}
}
inputFile.close();
// Read in artists:
/* int artistID;
string artistName; */
inputFile.open(c.artistFileName);
if (!inputFile)
{
cout << "Error opening artist file." << endl;
}
else
{
for (int i = 0; i < c.artistCount; i++)
{
getline(inputFile, temp);
artists[i].artistID = stoi(temp);
getline(inputFile, temp);
artists[i].artistName = temp;
}
}
inputFile.close();
inputFile.close();
// Read in b_a_Intercepts:
/* int albumID;
int artistID; */
inputFile.open(c.ABIFileName);
if (!inputFile)
{
cout << "Error opening album-artist intercept file." << endl;
}
else
{
for (int i = 0; i < c.B_A_IntCount; i++)
{
getline(inputFile, temp);
abint[i].albumID = stoi(temp);
getline(inputFile, temp);
abint[i].artistID = stoi(temp);
getline(inputFile,temp);
}
}
inputFile.close();
// Display library
cout << setw(15) << left << "Album Name" << "Artist(s)" << endl;
for (int i = 0; i < c.albumCount; i++)
{
cout << setw(15) << left << albums[i].albumName;
cout << setw(5) << albums[i].releaseDate;
for (int j = 0; j < c.B_A_IntCount; j++)
{
if(abint[j].albumID == albums[i].albumID)
{
//artistID = abint[j].artistID;
cout << artists[abint[j].artistID].artistName;
artistDisplayed++;
if (artistDisplayed <= albums[i].numArtists)
{
cout << ", ";
}
else
j = c.B_A_IntCount;
}
}
cout << endl;
}
}
void addAlbum(Config &c)
{
ofstream outputFile;
string albumName, artistName;
int albumID;
int releaseDate;
int numArtists;
int genreID;
cout << "Please enter the album's name: " ;
getline(cin, albumName);
cout << "Please enter the album ID (current autonumber is: " << (c.albumCount+1) << "): ";
cin >> albumID;
cout << "Please enter the album's release date (YYYY): ";
cin >> releaseDate;
cin.ignore(256,10);
cout << "How many artists are on the album (minumum 1, if unknown)? ";
cin >> numArtists;
outputFile.open(c.albumFileName, std::ios_base::app);
outputFile << albumID << endl;
outputFile << albumName << endl;
outputFile << releaseDate << endl;
outputFile << numArtists << endl;
outputFile.close();
c.albumCount++;
outputFile <<c.artistCount<<endl;
outputFile.close();
cin.ignore(256, 10);
for (int authCount = 0; authCount < numArtists; authCount++)
{
cout << "Enter the artist's name: " ;
getline(cin, artistName);
//Add artist to artist table
outputFile.open(c.artistFileName, std::ios_base::app);
outputFile << c.artistCount << endl;
outputFile << artistName << endl;
outputFile.close();
//Add the artist/album interception
outputFile.open(c.ABIFileName, std::ios_base::app);
outputFile << albumID << endl;
outputFile << c.artistCount << endl;
outputFile.close();
c.B_A_IntCount++;
c.artistCount++;
}
// Update Config File:
outputFile.open(c.configFileName);
outputFile << c.albumCount << endl;
outputFile << c.artistCount << endl;
outputFile << c.B_A_IntCount << endl;
outputFile.close();
}
void searchLibrary(Cnfig &c)
{
|