#include "stdstuff.h" #include "CustomerDB.h" // four methods included to help you out (as they are quite similar to // the other methods that involve going through the database) // returns the lowest customer ID of all customers // (returns -1 if there are no customers in the database) int CustomerDB::getLowestID() const { CNode *lowestIDptr; if(numCusts==0) return -1; // return -1 if database empty // assume first customer has the lowest id and check the rest lowestIDptr = head; for(CNode *c=head->next; c!=NULL; c=c->next) { if(c->cici) lowestIDptr = c; } return (lowestIDptr->ci).getID(); // return the lowest ID } // returns the highest total of all customers // (returns -1 if there are no customers in the database) double CustomerDB::getBestTotal() const { double maxtotal; if(numCusts==0) return -1; // return -1 if database empty // assume first total is largest and then check the rest maxtotal = (head->ci).getTotal(); // **must** use getTotal for(CNode *c=head->next; c!=NULL; c=c->next) { if((c->ci).getTotal()>maxtotal) // use getTotal maxtotal=(c->ci).getTotal(); // **must** use getTotal } return maxtotal; } // prints (to cout) the earliest purchase date of all customers // (prints 31 12 2099 if there are no customers in the database) void CustomerDB::outputFirstDate() const { Date max(31,12,2099); cout << "The first purchase date is: "; for(CNode *c=head->next; c!=NULL; c=c->next) { if((c->ci).getDate().compareTo(max)<0) // **must** use getDate max = (c->ci).getDate(); // **must** use getDate } max.write(cout); cout << endl; } // returns the customer name that's first in case insensitive alphabetical order // (returns "" if there are no customers in the database) String2002 CustomerDB::getFirstName() const { String2002 lowerFirstName, firstName, lowerName, name; if (numCusts==0) return ""; // return empty string if no customers // start with index 0 as the first name (convert to lower case) name = (head->ci).getName(); // **must** use getName lowerFirstName = name; firstName = name; for(int i=0;i<(int)lowerFirstName.length();i++) lowerFirstName[i] = tolower(lowerFirstName[i]); // go through the rest, checking to see if each (converted to lower // case) is the first one so far for(CNode *c=head->next; c!=NULL; c=c->next) { name = (c->ci).getName(); // **must** use getName lowerName = name; for(int j=0;j<(int)lowerName.length();j++) lowerName[j] = tolower(lowerName[j]); if(lowerName