int main() { Thesaurus thesaurus; // Fill with 10 entries: generate_n( inserter(thesaurus, thesaurus.begin()), 10, ThesaurusGen()); // Print everything: copy(thesaurus.begin(), thesaurus.end(), ostream_iterator<TEntry>(cout, "\n")); // Create a list of the keys: string keys[10]; int i = 0; for(TIter it = thesaurus.begin(); it != thesaurus.end(); it++) keys[i++] = (*it).first; for(int count = 0; count < 10; count++) { // Enter from the console: // string reply = menu(thesaurus); // Generate randomly (for automated testing): string reply = keys[rand() % 10]; vector<string>& v = thesaurus[reply]; copy(v.begin(), v.end(), ostream_iterator<string>(cout, " ")); cout << endl; } } ///:~
int main() { Thesaurus thesaurus; // Fill with 10 entries: generate_n( inserter(thesaurus, thesaurus.begin()), 10, ThesaurusGen()); // Print everything: copy(thesaurus.begin(), thesaurus.end(), ostream_iterator<TEntry>(cout, "\n")); // Ask for a "word" to look up: while(true) { cout << "Select a \"word\", 0 to quit: "; for(TIter it = thesaurus.begin(); it != thesaurus.end(); it++) cout << (*it).first << ' '; cout << endl; string reply; cin >> reply; if(reply.at(0) == '0') return 0; // Quit if(thesaurus.find(reply) == thesaurus.end()) continue; // Not in list, try again vector<string>& v = thesaurus[reply]; copy(v.begin(), v.end(), ostream_iterator<string>(cout, " ")); cout << endl; } } ///:~
// Ask for a "word" to look up: string menu(Thesaurus &thesaurus) { while(true) { cout << "Select a \"word \" , 0 to quit: "; for(TIter it = thesaurus.begin(); it != thesaurus.end(); it++) cout << (*it).first << ' '; cout << endl; string replay; cin >> replay; if(replay.at(0) == '0') exit(0); if(thesaurus.find(replay) == thesaurus.end()) continue; // Not in list, try again return replay; } }
int main() { srand(time(0)); Thesaurus thesaurus; // Fill with 10 entries: generate_n(inserter(thesaurus, thesaurus.begin()), 10, ThesaurusGen()); // Print evetythins: copy(thesaurus.begin(), thesaurus.end(), ostream_iterator<TEntry>(cout, "\n")); // Create a list of the keys: string keys[10]; int i = 0; for(TIter it = thesaurus.begin(); it != thesaurus.end(); it++) keys[i++] = (*it).first; for(int count = 0; count < 10; count++) { // Entry from the console: string replay = keys[rand() % 10]; vector<string> &v = thesaurus[replay]; copy(v.begin(), v.end(), ostream_iterator<string>(cout, " ")); cout << endl; } }