// CSE143 Sp01 Homework 1 Sample Solution // hw1sol.cpp - main program // SRB 6/20 #include #include #include using namespace std; #include "wordlist.h" // Read words data from "words.txt" and stores in WordList instance // Returns true if successful; otherwise returns false bool readWordList(WordList &words) { string badWord, goodWord; // Misspelled and correctly spelled word // Attempt to open file; quit if unsuccessful ifstream data("words.txt"); if (!data) { return false; } // read data from file data >> badWord >> goodWord; while (badWord != ".") { addWord(words, badWord, goodWord); data >> badWord >> goodWord; } return true; } // Handles user interaction, breaks the sentence into individual words, and //queries the WordList for each one. Prints out the corrected work, on the fly, //to the screen void correctSentences(WordList &words) { char sentence[200]; string correctWord; // string representing the correctly spelled word int numErrors=0; // total number of errors char seps[] = " ,!.?"; // denotes seperator for the tokens char *token; // points to the current token int found=0; // stores if a match was made in the WordList cout << "Please enter your sentence or a period to stop:" << endl; gets( sentence ); while (sentence[0] != '.') { //initializes the 1st token token = strtok( sentence, seps ); while( token != NULL ) { //Retrieves the correctly spelled version of the word queryWordList(words,token,correctWord,found); numErrors += found; cout<