#ifndef WORDUTILS_H
#define WORDUTILS_H
#include <string>
std::string lowercase (const std::string& s);
// Converts all upper-case alphabetic characters in s to the
// corresponding lowercase characters.
// Example: lowercase("ABcdE?") should return "abcde?"
std::string stem (const std::string& word);
// Tries to guess the stem form of an English word by applying
// the following rules: (# and % stand for any consonant, and
// @ for any vowel [aeiou].
//
// If word ends in: replace it by: example:
// ies y flies => fly
// ied y carried => carry
// ier y merrier => merry
// iest y merriest => merry
// ##ed # hitted => hit
// ##ing # hitting => hit
// ##er # hitter => hit
// ##est # hottest => hot
// %@#ed %@#e glided => glide
// %@#ing %@#e gliding => glide
// %@#er %@#e glider => glide
// %@#est %@#e palest => pale
// #ed # barked => bark
// #ing # boiling => boil
// #er # colder => cold
// #est # coldest => cold
// #s # things => thing
// If none of the above rules apply, then the word is assumed to be already
// in its stem form. This function returns the stem that it guesses.
// [Note that these really are guesses - it isn't hard to find words on which
// these rules fail. E.g., "pies"]
//
#endif
//New functions
collectMisspelledWords (/* inputs */ targetFile, dictionaryFile,
/* outputs */ misspellings)
{
read dictionaryFile into dictionary;
open targetFile;
misspellings = empty;
while more words in targetFile {
read word w from targetFile;
w = LOWERCASE(w);
if ((w is not in dictionary) &&
(STEM(w) is not in dictionary))
{
add w to misspellings;
}
}
close targetFile;
}
The two functions capitalized are new. I am trying to write the bodies for the two string manipulation functions, as declared in the wordutils.h. The two functions should work entirely through the std::string interface - no character arrays.