// SYSC 2002 Winter 2011 Assignment #2 #include "stdstuff.h" // global constants const int MAXOPT=7, MAXCUST=100; // Hint: make MAXCUST much smaller to test filling the database // "customer" is the struct containing the customer information // it is made up of id (an integer) and total (a double) struct customer{ int id; double total; }; // Complete the functions here. Note that the students can be stored in any order. // add a new customer to the database; returns true if successful, false otherwise // (database full or customer already exists) bool addCustomer(int id, double total, customer db[], int &num) { if(num==MAXCUST) return false; // database is full for(int i=0;imaxtotal) maxtotal=db[i].total; } return maxtotal; } // 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, numCusts=0; int id, newid; double total, newtotal, maxtotal; // the Customer database (with numCusts customers in it) customer customerinfo[MAXCUST]; 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,customerinfo,numCusts)) cout << "Customer added. There are now: " << 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,customerinfo,numCusts)) cout << "Customer removed. There are now: " << 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(customerinfo,numCusts); break; case 4: // change customer id cout << "Enter existing customer id, and new customer id: "; cin >> id >> newid; if(changeCustomerID(id,newid,customerinfo,numCusts)) 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,customerinfo,numCusts)) 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(customerinfo,numCusts); 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; }