// SYSC 2002 Winter 2011 Assignment #3 #include "stdstuff.h" #include "customerDB.h" // global constant const int MAXOPT=7; // 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: Find Best Customer Total" << endl; cout << "7: 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; double total, newtotal, maxtotal; // the Customer database (no customers when we start) customerDB ourDB; ourDB.numCusts=0; for(;;){ option=mainMenu(); if(option==MAXOPT) break; // end of program switch(option) { case 1: // add new customer cout << "Enter customer id and total: "; cin >> id >> total; if(addCustomer(id,total,ourDB)) cout << "Customer added. There are now: " << ourDB.numCusts << " 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(removeCustomer(id,ourDB)) cout << "Customer removed. There are now: " << ourDB.numCusts << " 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 line, with total to 2 // decimal places printCustomerDatabase(ourDB); break; case 4: // change customer id cout << "Enter existing customer id, and new customer id: "; cin >> id >> newid; if(changeCustomerID(id,newid,ourDB)) 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(changeCustomerTotal(id,newtotal,ourDB)) cout << "Customer total successfully updated.\n"; else cout << "Customer could not be updated: did not exist in database.\n"; break; case 6: // find best customer total maxtotal = getBestCustomerTotal(ourDB); if(maxtotal==-1) cout << "No customers: database is empty.\n"; else cout << "Best customer total is: " << maxtotal << ".\n"; break; default: // should never get here break; } } pause(); return 0; }