# include # include # include "icecream.C" # include "string.C" # include "rstream.h" # include "rstream.c" unsigned int hf(const iceCreamRecord & x) { string name(x.name()); return name[2] - 'a'; } # include "openHashTable.h" # include "openHashTable.c" template class openHashTableIterator : public rstreamIterator { public: openHashTableIterator(openHashTable &); virtual int operator ++ (); virtual void operator = (T value); }; template openHashTableIterator::openHashTableIterator(openHashTable & t) : rstreamIterator(t.rfile) { // nothing more } template int openHashTableIterator::operator ++() { if (rstreamIterator::operator ++() == 0) return 0; if (isEmpty(operator()())) return operator ++ (); return 1; } template void openHashTableIterator::operator = (T value) { rstreamIterator::operator = (value); } openHashTable hashtab("/tmp/openHashTableFile", hf); openHashTableIterator itr(hashtab); main() { string name(80); string flavor(80); cout << "enter name:\n"; cin >> name; for (itr.init(); ! itr; itr++) if (name == itr().name()) { cout << "enter flavor:\n"; cin >> flavor; iceCreamRecord newRec(name, flavor); itr = newRec; return 0; } cout << "name not found in database\n"; return 0; }