// SYSC 2002 Winter 2011 Assignment #6 #include "stdstuff.h" //#include "Date.h" (this is needed at the beginning of Customer.h) //#include "Customer.h" (this is needed at the beginning of CustomerDB.h) #include "CustomerDB.h" // global constant const int MAXOPT=12; // mainMenu returns an integer representing the menu option chosen // Valid values are from 1 to "MAXOPT" (global constant). int mainMenu(){ int returnVal; for(;;){ cout << endl; cout << "1: Add New Customer" << endl; cout << "2: Remove Existing Customer" << endl; cout << "3: Print Database Information" << endl; cout << "4: Change Existing Customer ID" << endl; cout << "5: Change Existing Customer Total" << endl; cout << "6: Move Existing Customer Purchase Date" << endl; cout << "7: Append Existing Customer Name" << endl; cout << "8: Find Lowest Customer ID" << endl; cout << "9: Find Best Customer Total" << endl; cout << "10: Find First Customer Purchase Date" << endl; cout << "11: Find First Customer Name" << endl; cout << "12: End Program\n\n"; // always use "max" for ending program cout << "Please enter the desired operation [1-" << MAXOPT << "]: "; cin >> returnVal; //return if valid option, otherwise output error message if(returnVal>=1&&returnVal<=MAXOPT) return returnVal; cout << "Please enter a valid integer option!" << endl; ; } } // main program calls the functions most of which you need to write int main(){ int option; int id, newid, numDays, lowID; double total, newtotal, maxtotal; Date purchase; String2002 firstName, name, toAppend; // the Customer database (no customers when we start) -- it uses the default constructor CustomerDB ourDB; // ourDB.numCusts=0; // this is now done in the default constructor for(;;){ option=mainMenu(); if(option==MAXOPT) break; // end of program switch(option) { case 1: // add new customer cout << "Enter customer id, total, purchase date (DD MM YYYY) and name: "; cin >> id >> total; purchase.read(cin); cin.get(); // remove '\n' so getline works getline(cin,name,'\n'); // name can now contain spaces (and other special characters) if(ourDB.add(Customer(id,total,purchase,name))) cout << "Customer added. There are now: " << ourDB.getNumCusts() << " customers in database.\n"; else cout << "Customer could not be added: already in database or database full.\n"; break; case 2: // remove existing Customer cout << "Enter customer id: "; cin >> id; if(ourDB.remove(id)) cout << "Customer removed. There are now: " << ourDB.getNumCusts() << " Customers in database.\n"; else cout << "Customer could not be removed: did not exist in database.\n"; break; case 3: // print database information, one customer per 2 lines, with total to 2 // decimal places ourDB.print(); break; case 4: // change customer id cout << "Enter existing customer id, and new customer id: "; cin >> id >> newid; if(ourDB.changeID(id,newid)) cout << "customer id successfully updated.\n"; else cout << "Customer could not be updated: did not exist in database or new id in use.\n"; break; case 5: // change Customer total cout << "Enter customer id, and new Customer total: "; cin >> id >> newtotal; if(ourDB.changeTotal(id,newtotal)) cout << "Customer total successfully updated.\n"; else cout << "Customer could not be updated: did not exist in database.\n"; break; case 6: // move customer purchase date cout << "Enter customer id, and number of days to move purchase date: "; cin >> id >> numDays; if(ourDB.moveDate(id,numDays)) cout << "Customer purchase date successfully updated.\n"; else cout << "Cutomer could not be updated: did not exist in database.\n"; break; case 7: // append customer name cout << "Enter customer id, and string to append to name: "; cin >> id >> toAppend; if(ourDB.appendName(id,toAppend)) cout << "Customer name successfully updated.\n"; else cout << "Customer could not be updated: did not exist in database.\n"; break; case 8: // find lowest customer ID (returns -1 if database empty) lowID = ourDB.getLowestID(); if(lowID==-1) cout << "No customers: database is empty.\n"; else cout << "Lowest customer ID is: " << lowID << ".\n"; break; case 9: // find best customer total maxtotal = ourDB.getBestTotal(); if(maxtotal==-1) cout << "No customers: database is empty.\n"; else cout << "Best customer total is: " << maxtotal << ".\n"; break; case 10: // output first customer purchase date (31 12 2099 if no customers) ourDB.outputFirstDate(); break; case 11: // find first customer name (case *insensitive*) firstName = ourDB.getFirstName(); if(firstName=="") cout << "No customers: database is empty.\n"; else cout << "First customer name (case insensitive) is: " << firstName << ".\n"; break; default: // should never get here break; } } pause(); return 0; }