///////////////////////////////////////////////////////////////// // equivStr.cpp - defines an alternate set of equivalence // // properties for standard C++ string objects // // // // Language: Visual C++, ver 5.0 // // Platform: Micron Dual Pentium 200, NT 4.0 // // Application: CSE687 - Object Oriented Design, Spring 04 // // Author: Jim Fawcett, CST 2-187, (314) 443-3948 // // fawcett@neptune.syr.edu // ///////////////////////////////////////////////////////////////// #include #include "equivStr.h" //----< near matches between standard strings >---------------- bool nearStr::equiv(const nearStr &rhs) const { // equivalent if first five chars are same (case insensitive) int i; for(i=0; i--------------- bool nearStr::less(const nearStr &rhs) const { int i; for(i=0; i-------------------------- bool noCaseStr::equiv(const noCaseStr &rhs) const { if(size() != rhs.size()) return false; int i; for(i=0; i-------------------------------- bool noCaseStr::less(const noCaseStr &rhs) const { int i; for(i=0; i void main() { nearStr ns[5] = { "Stroustrup", "strou", "Stro", "Stroustrups", "Stroustrup's" }; noCaseStr nc[5] = { "Bjarne", "bjarne", "BJARNE", "Bjarne's", "Bjar" }; cout << "\n Test Near Matching:" << "\n =====================\n\n"; int i; for(i=0; i<5; i++) if(ns[0]==ns[i]) cout << " " << ns[0] << " == " << ns[i] << '\n'; else cout << " " << ns[0] << " != " << ns[i] << '\n'; for(i=0; i<5; i++) if(ns[0]= " << ns[i] << '\n'; cout << "\n Test Case Insensitive Matching:" << "\n =================================\n\n"; for(i=0; i<5; i++) if(nc[0] == nc[i]) cout << " " << nc[0] << " == " << nc[i] << '\n'; else cout << " " << nc[0] << " != " << nc[i] << '\n'; for(i=0; i<5; i++) if(nc[0] < nc[i]) cout << " " << nc[0] << " < " << nc[i] << '\n'; else cout << " " << nc[0] << " >= " << nc[i] << '\n'; cout << endl; } #endif