//Stub.cpp //Driver for CD database //CS 2 #include #include "apstring.h" #include "apvector.h" #include struct cdType { apstring artist; apstring album; }; void menu() { cout<<"A)dd"< &myCollection) { for (int x=0; x<=myCollection.length()-1; x++) cout << x+1 << ") " << myCollection[x].artist << "\t\t-\t" << myCollection[x].album << endl << endl << endl; } void add(apvector &myCDs) { cdType temp; int len = myCDs.length(); myCDs.resize(len+1); cout << "Name of artist ... "; getline(cin, temp.artist); cout << "Name of album ... "; getline(cin, temp.album); bool done = false; int i = len - 1; while (!done && i >= 0) { if (temp.artist < myCDs[i].artist) { myCDs[i+1] = myCDs[i]; i--; } else { myCDs[i+1] = temp; done = true; } } if (!done) myCDs[0] = temp; } void edit (apvector &myCollection) { apstring userSearch; cout << "What is the name of the album that you would like to edit?" << endl; cin >> userSearch; bool found; for (int x=0; x &myCollection) { ofstream fout; apstring line; fout.open("C:\\cdCollection\database\txt"); getline (cin, line); fout << line; fout << endl; fout.close; } void readFile (apvector &myCollection) { ifstream fin; int num; apstring garbage; fin.open("C:\\cdCollection\database.txt", ios::nocreate); if (!fin) { cout << "File not found. Please recreate an empty .txt file under the directory" << endl << "C:\\cdCollection\\database.txt" << endl; system ("pause"); system ("cls"); } fin >> num; getline(fin, garbage); myCollection.resize(num); for (int i=0; i myCollection; readFile (myCollection); char ch; apstring response; apstring legal="AaEePpQq"; do { do { menu(); getline(cin,response); ch = response[0]; }while(response.find(ch)==-1); switch(ch) { case 'a': case 'A': add (myCollection);break; case 'E': case 'e': edit (myCollection);break; case 'P': case 'p': print (myCollection);break; case 's': case 'S': writeFile (myCollection);break; case 'q': case 'Q': break; } system("pause"); system("cls"); }while(ch!='q' && ch!= 'Q'); cout<