/*=========================================================================*/ // // Stores possessed and desired attributes for customers // class Attributes { friend ostream &operator<<(ostream &out, const Attributes &a); friend istream &operator>>(istream &in, Attributes &a); public: Attributes(); bool match(const Attributes &a); void print(); private: // ... }; // Attributes class /*=========================================================================*/ // // Self-referential class that stores the customer's name and the // possessed and desired attributes. // class Customer { friend ostream& operator<<(ostream &out, const Customer &c); friend istream& operator>>(istream &in, Customer &c); public: Customer(); string getName(); void setName(string name); // ... Customer *getNext(); void setNext(Customer *next); bool match(const Customer &c); void print(); private: string name; Attributes possess; Attributes desired; Customer *next; }; // Customer class /*=========================================================================*/ // // Implements a linked list of Customer objects. // class CustomerList { public: CustomerList(); bool empty(); void save(string filename); void load(string filename); bool remove(string name); void print(); Customer *match(string name); void clear(); ~CustomerList(); private: Customer *find(string name); Customer *first; }; // CustomerList Class bool CustomerList::empty() --- returns true if the linked list of customers is empty; return false otherwise. void CustomerList::save(string filename) --- writes the information for each customer in the linked list to the output file 'filename'. void CustomerList::load(string filename) --- loads customer information from the file 'filename', storing it in a linked list. bool CustomerList::remove(string name) --- removes a single customer object from the linked list with the name 'name'. Returns true if the operation succeeds; returns false otherwise. void CustomerList::print() -- Prints a customer records in a "pretty" format. Customer *CustomerList::match(string name) --- Give a customer's name, finds another customer who matches. If found, then returns a pointer to the matching customer object in the linked list; returns a null pointer otherwise. void CustomerList::clear() --- Destructs all of the customer objects in the linked list. Customer *CustomerList::find(string name) --- Given a customer's name, traverses the linked list, searching for a customer object with the same name. If found, returns a pointer to that object; returns a null pointer otherwise. CustomerList::~CustomerList() -- Destructor method, which destructs all of the customer objects in the linked list. Should call clear(). /*=========================================================================*/ class MatcherApp { public: MatcherApp(string filename); void processCommands(); private: void printMenu(); void loadCustomers(); void saveCustomers(); void printCustomers(); void matchCustomer(); void removeCustomer(); void clearCustomers(); string filename; CustomerList customers; }; // MatcherApp MatcherApp::MatcherApp(string filename) --- Stores filename in the private data member filename and loads the CustomerList. void MatcherApp::processCommands() --- Command loop. Prints the menu, takes a command, executes it, until the user quits. void MatcherApp::printMenu() --- Prints the menu of commands. void MatcherApp::loadCustomers() --- Loads Customers into the CustomerList using the name stored in the private data member filename. void MatcherApp::saveCustomers() --- Saves the Customers in the CustomerList to the file name stored in the private data member filename. void MatcherApp::printCustomers() --- Prints the records in the CustomerList. void MatcherApp::matchCustomer() --- Gets the name of a customer from the user, prints the customer in CustomerList who matches. void MatcherApp::removeCustomer() --- Gets the name of a customer and removes that customer from the CustomerList. void MatcherApp::clearCustomers() --- Clears CustomerList /*=========================================================================*/ int main() { MatcherApp matcher("maloofm.dta"); matcher.processCommands(); return 0; } // main