#include #include #include "concordance.h" const int QUIT = 1; const int PRINTALL = 2; const int PRINTONE = 3; const int PRINTFREQ = 4; const int COUNTWORDS = 5; const char *FILENAME = "proj3.dat"; // forward declarations int menu (void); void strlower (char *s); main () { Concordance c; int choice; char aWord[256]; int freq; // read the file and insert words ifstream datafile(FILENAME, ios::in); if (!datafile) { cout << endl << "Unable to open " << FILENAME << endl; exit (1); } while (datafile >> aWord) { strlower (aWord); c.Insert (aWord); } while ((choice = menu()) != QUIT) switch (choice) { case PRINTALL: // all words in alphabetical order c.PrintWords (0); break; case PRINTONE: // number of occurrences of a word cout << "Enter word to find: " << flush; cin >> aWord; c.PrintAWord (aWord); break; case PRINTFREQ: // all words with count >= input cout << "Enter minimum frequency: " << flush; cin >> freq; cout << "List of words that occur at least " << freq << " times: " << endl; c.PrintWords (freq); cout << endl; break; case COUNTWORDS: cout << "The concordance contains " << c.CountWords() << " distinct words" << endl << endl; break; default: cout << "Invalid menu choice, please try again" << endl << endl; } } //************************************* // int menu () // // output menu and get user input // //********************************* int menu () { cout << "Please choose from the following options:" << endl; cout << " 1. Quit" << endl; cout << " 2. Print all words alphabetically" << endl; cout << " 3. Show frequency of a particular word" << endl; cout << " 4. Print all words that appear more than N times" << endl; cout << " 5. Display the number of distinct words" << endl; cout << endl; cout << "Option: " << flush; int option; cin >> option; return option; } #include void strlower (char *s) { while (*s) { *s = tolower(*s); s++; } }