// From the software distribution accompanying the textbook // "A Practical Introduction to Data Structures and Algorithm Analysis, // Third Edition" by Clifford A. Shaffer, Prentice Hall, 2007. // Source code Copyright (C) 2006 by Clifford A. Shaffer. // Test driver for the payroll class. Mainly a syntax check. // The purpose of this class is to demonstrate simple comparators. #include using namespace std; #include "book.h" // Include comparator functions #include "compare.h" // Use an array-based list #include "alist.ht" // Implement a dictionary with an unsorted array-based list #include "UALdict.ht" // Implementation for Payroll class // A simple payroll entry with ID, name, address fields class Payroll { private: int ID; char* name; char* address; public: // Constructor Payroll(int inID, char* inname, char* inaddr) { ID = inID; name = inname; address = inaddr; } ~Payroll() {} // Destructor // Data member access functions int getID() { return ID; } char* getname() { return name; } char* getaddr() { return address; } }; class getID { // Use the ID field as a key public: static int key(Payroll* e) { return e->getID(); } }; class getname { // Use the name field as a key public: static char* key(Payroll* e) { return e->getname(); } }; class getaddr { // Use the addr field as a key public: static char* key(Payroll* e) { return e->getaddr(); } }; // Overload << operator to print Payroll records ostream& operator << (ostream& s, Payroll* p) { return s << p->getID() << ", " << p->getname() << ", " << p->getaddr() << endl; } // Driver main routine to test the payroll entry comparators int main(int argc, char** argv) { UALdict IDdict; UALdict namedict; Payroll *foo1, *foo2, *findfoo1, *findfoo2; foo1 = new Payroll(5, "Joe", "Anytown"); foo2 = new Payroll(10, "John", "Mytown"); IDdict.insert(foo1); IDdict.insert(foo2); namedict.insert(foo1); namedict.insert(foo2); if(IDdict.find(5, findfoo1)) cout << findfoo1; if(namedict.find("John", findfoo2)) cout << findfoo2; }