// From the software distribution accompanying the textbook // "A Practical Introduction to Data Structures and Algorithm Analysis, // Third Edition (C++)" by Clifford A. Shaffer. // Source code Copyright (C) 2007-2011 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 "book.h" // Use an array-based list #include "alist.h" // Implement a dictionary with an unsorted array-based list #include "UALdict.h" // Implementation for Payroll class // A simple payroll entry with ID, name, address fields class Payroll { private: int ID; string name; string address; public: // Constructor Payroll(int inID, string inname, string inaddr) { ID = inID; name = inname; address = inaddr; } ~Payroll() {} // Destructor // Local data member access functions int getID() { return ID; } string getname() { return name; } string getaddr() { return address; } }; // 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() { // IDdict organizes Payroll records by ID UALdict IDdict; // namedict organizes Payroll records by name UALdict namedict; Payroll *foo1, *foo2, *findfoo1, *findfoo2; foo1 = new Payroll(5, "Joe", "Anytown"); foo2 = new Payroll(10, "John", "Mytown"); IDdict.insert(foo1->getID(), foo1); IDdict.insert(foo2->getID(), foo2); namedict.insert(foo1->getname(), foo1); namedict.insert(foo2->getname(), foo2); findfoo1 = IDdict.find(5); if (findfoo1 != NULL) cout << findfoo1; else cout << "NULL "; findfoo2 = namedict.find("John"); if (findfoo2 != NULL) cout << findfoo2; else cout << "NULL "; }