// File: albumdriver.cpp
// This program allows the user to test the Album class
//
// ----------------------------------------------------------------------
// Class: CS 210                         Instructor: Drs. Hwang & Roberts
// Assignment: Programming Assignment 7  Date assigned: April 2/3, 2007
// Programmer: <fill in your name>       Date completed: <fill in the date>

#include <iostream>    // cin, cout, <<, >>, endl
#include <string>      // string
#include <cstdlib>     // srand()
#include <ctime>       // time()
#include "album.h"     // Album class
using namespace std;

// Function prototypes
char PrintMenuAndGetChoice ();
void GetNewInfo (string& newArtist, string& newTitle, string& newGenre, 
                 int & newYear, vector<string> & newTracks, int& newRating);

int main ()
{
   Album theAlbum, anotherAlbum; // Default construction
   char choice;                  // Menu choice
   string newArtist,             // Variables for user inputs and return values
          newTitle,   
          newGenre,
          songTitle;
   int newYear,
       newRating;
   vector<string> newTracks;

   cout << "This is a driver program to test the Album class\n";

   // Seed the pseudo-random number generator
   srand((unsigned int)(time(0)));

   // Print menu and read in first choice
   choice = PrintMenuAndGetChoice();

   // Repeat until user wants to quit
   while ((choice != 'Q') && (choice != 'q'))
   {
      cout << endl;
      // Process choice
      switch (choice)
      {
         case 'A': case 'a':  // Default construction of first Album
            theAlbum = Album();
            break;
         case 'B': case 'b': // Explicit construction of second Album
            GetNewInfo (newArtist, newTitle, newGenre, newYear, newTracks, newRating);
            anotherAlbum = Album (newArtist, newTitle, newGenre, newYear,
                                newTracks, newRating);
            break;
         // Accessor tests
         case 'C': case 'c':
            cout << "The artist of the first Album is " << theAlbum.Artist() 
                 << "\nThe artist of the second Album is " << anotherAlbum.Artist()
                 << endl;
            break;
         case 'D': case 'd':
            cout << "The title of the first Album is " << theAlbum.Title() 
                 << "\nThe title of the second Album is " << anotherAlbum.Title()
                 << endl;
            break;
         case 'E': case 'e':
            cout << "The genre of the first Album is " << theAlbum.Genre()
                 << "\nThe genre of the second Album is " 
                 << anotherAlbum.Genre() << endl;
            break;
         case 'F': case 'f':
            cout << "The first Album was recorded in " << theAlbum.Year() 
                 << "\nThe second Album was recorded in " 
                 << anotherAlbum.Year() << endl;
            break;
         case 'G': case 'g':
            cout << "The first Album's rating is " << theAlbum.Rating() 
                 << "\nThe second Album's rating is " << anotherAlbum.Rating() 
                 << endl;
            break;
         case 'H': case 'h':  // see if song is in track list
            cout << "Please enter the song title: ";
            cin >> songTitle;
            if (theAlbum.HasTrack (songTitle))
               cout << '\n' << songTitle 
                    << " is on the first Album's track list\n";
            else
               cout << '\n' << songTitle 
                    << " is not on the first Album's track list\n";
            if (anotherAlbum.HasTrack (songTitle))
               cout << '\n' << songTitle 
                    << " is on the second Album's track list\n";
            else
               cout << '\n' << songTitle 
                    << " is not on the second Album's track list\n";
            break;
         case 'I': case 'i':  // find a random track
            cout << "A random track from the first Album is " 
                 << theAlbum.RandomTrack()
                 << "\nA random track from the second Album is "
                 << anotherAlbum.RandomTrack() << endl;
            break;
         // Mutator tests
         case 'J': case 'j':  // change user rating
            cout << "Please enter the new rating for the second Album: ";
            cin >> newRating;
            anotherAlbum.ChangeRating (newRating);
            break;
         case 'K': case 'k':  // add a song title to track list
            cout << "Please enter the song title (no spaces) to add to \n"
                 << "the track list of the first Album: ";
            cin >> songTitle;
            theAlbum.AddTrack (songTitle);
            break;
         // Operator tests
         case 'L': case 'l':  // check operator==
            if (theAlbum == anotherAlbum)
               cout << "The first Album has the same artist and title as "
                    << "the second Album";
            else
               cout << "The first Album does not have the same artist and title"
                    << " as the second Album";
            break;
         case 'M': case 'm':  // check operator<
            if (theAlbum < anotherAlbum)
               cout << "The first Album, " << theAlbum.Title() 
                    << " has a lower rating than the second album "
                    << anotherAlbum.Title() << endl;
            else
               cout << "The second Album, " << anotherAlbum.Title() 
                    << " has a lower rating than the first album "
                    << theAlbum.Title() << endl;
            break;
         case 'N': case 'n':  // input from keyboard
            cout << "Please enter the new data in the following order:\n"
                 << "artist, title, genre, year,\n"
                 << "track list ending in END_OF_TRACKLIST,\n"
                 << "and rating separated by spaces or newlines:\n";
            cin >> theAlbum;
            break;
         case 'O': case 'o':  // output to screen
            cout << "The first Album's information is: \n" << theAlbum << endl;
            cout << "\nThe second Album's information is: \n" << anotherAlbum << endl;
            break;
         default:
           cout << "Not a valid choice, please try again\n";
      }  // end switch

      // Print menu and read in next choice
      choice = PrintMenuAndGetChoice();
   } // end while

   return 0;
}  // end main


// Function: PrintMenuAndGetChoice
// Prints a menu of choices and returns the user's choice
char PrintMenuAndGetChoice ()
{
   char choice;
   cout << "\n\nPlease choose a Album operation from the following "
        << "list:\n\n"
        << "   A. Default construction\n"
        << "   B. Explicit construction\n"
        << "   C. Get the artist\n"
        << "   D. Get the title\n"
        << "   E. Get the genre\n"
        << "   F. Get the year of recording\n"
        << "   G. Get the rating\n"
        << "   H. Find song title in track list\n"
        << "   I. Get random song title\n"
        << "   J. Change user rating\n"
        << "   K. Add song title to track list\n"
        << "   L. Test operator==\n"
        << "   M. Test operator<\n"
        << "   N. Input using >>\n"
        << "   O. Display using <<\n\n"
        << "   Q. Quit program\n\n"
        << "Please enter your choice: ";
   cin >> choice;
   return choice;
}  // end PrintMenuAndGetChoice
  
      
// Function: GetNewInfo
// Asks the user and passes back an artist, a title, genre, a year, 
// a track list, and user's rating
void GetNewInfo (string & newArtist,          // PASSED BACK: artist of Album
                 string & newTitle,           // PASSED BACK: title of Album
                 string & newGenre,           // PASSED BACK: genre of Album
                 int & newYear,               // PASSED BACK: year of Album
                 vector<string> & newTracks,  // PASSED BACK: tracks of Album
                 int & newRating)             // PASSED BACK: rating of Album
{
   string song;

   cout << "Please enter the new artist: ";
   cin >> newArtist;
   cout << "Please enter the new title: ";
   cin >> newTitle;
   cout << "Please enter the new genre: ";
   cin >> newGenre;
   cout << "Please enter the new year: ";
   cin >> newYear;

   newTracks.clear();  // make sure vector is empty
   cout << "Please enter the song titles separated by spaces\n"
        << "and ending with END_OF_TRACKLIST\n";
   cin >> song;
   while (song != "END_OF_TRACKLIST")
   {
      newTracks.push_back(song);
      cin >> song;
   }  // end for

   cout << "Please enter the new rating: ";
   cin >> newRating;
}  // end GetNewInfo
