//----------------------------------------------------------------------------- // DictionaryClient.cpp // A test client for the Dictionary ADT //----------------------------------------------------------------------------- #include #include #include #include"Dictionary.h" using namespace std; int main(){ string s; int x; string S[] = { "plaices", "ambusher", "crosby", "wattles", "pardoner", "pythons", "second", "forms", "impales", "pic", "verticals", "recriminator", "depressants", "cul", "potables", "norm", "reinsurer", "deschooler", "recoining", "dissocialised", "cohabit", "hemiolia", "cantling", "glamorized", "millesimal", "glagolitic" }; string T[] = { "second", "forms", "impales", "pic", "verticals", "recriminator", "depressants", "cul", "potables", "norm", "reinsurer", "deschooler", "recoining", }; Dictionary A; Dictionary B; cout << endl; // insert some pairs into A for(int i=0; i<26; i++){ A.setValue(S[i], i+1); } // call operator=() B = A; cout << "A.size() = " << A.size() << endl << A << endl; cout << "B.size() = " << B.size() << endl << B << endl; B.setValue("deschooler", 101); B.setValue("reinsurer", 102); B.setValue("glagolitic", 103); B.setValue("cul", 104); B.setValue("ambusher", 105); // call copy constructor Dictionary C = B; cout << "B.size() = " << B.size() << endl << B << endl; cout << "C.size() = " << C.size() << endl << C << endl; // check operator==() cout << "A==B is " << (A==B?"true":"false") << endl; cout << "B==C is " << (B==C?"true":"false") << endl; cout << "C==A is " << (C==A?"true":"false") << endl << endl; // perform alterations on A cout << A.getValue("hemiolia") << endl; A.getValue("hemiolia") *= 10; // change the value associated with "hemiolia" cout << A.getValue("hemiolia") << endl << endl; // check state of A cout << "A.size() = " << A.size() << endl << A << endl; cout << A.pre_string() << endl; // remove some pairs from A for(int i=0; i<13; i++){ cout << "removing " << T[i] << " from Dictionary A" << endl; A.remove(T[i]); } cout << "after remove loop" << endl; // check state of A cout << "A.size() = " << A.size() << endl << A << endl; cout << A.pre_string() << endl; // do forward iteration on A for(A.begin(); A.hasCurrent(); A.next()){ s = A.currentKey(); x = A.currentVal(); cout << "("+s+", " << x << ") "; } cout << endl << endl; // do reverse iteration on A for(A.end(); A.hasCurrent(); A.prev()){ s = A.currentKey(); x = A.currentVal(); cout << "("+s+", " << x << ") "; } cout << endl << endl; // check exceptions try{ A.getValue("blah"); }catch(logic_error& e){ cout << e.what() << endl; cout << " continuing without interruption" << endl; } try{ A.remove("blah"); }catch(logic_error& e){ cout << e.what() << endl; cout << " continuing without interruption" << endl; } try{ A.currentKey(); }catch(logic_error& e){ cout << e.what() << endl; cout << " continuing without interruption" << endl; } try{ A.currentVal(); }catch(logic_error& e){ cout << e.what() << endl; cout << " continuing without interruption" << endl; } try{ A.next(); }catch(logic_error& e){ cout << e.what() << endl; cout << " continuing without interruption" << endl; } try{ A.prev(); }catch(logic_error& e){ cout << e.what() << endl; cout << " continuing without interruption" << endl; } cout << endl; return( EXIT_SUCCESS ); }