The goal of the program is to produce a count of the number of times each word occurs in Macbeth, except that a group of common words (and, to, be, etc.) are not to be included in the count. the program should read the words to be excluded from a file and store them in a set. When counting it should check whether the words in the set appear in macbeth and ignore it if so.
string StringToLower(string strToConvert) {//change each element of the string to lower case
for (unsigned int i = 0; i < strToConvert.length(); i++) {
strToConvert[i] = tolower(strToConvert[i]);
}
return strToConvert;//return the converted string
}
string TrimHeadPunc(string word) {
int index;
//remove any punctuations at head of the word
while ((index = word.find_first_of(".,!?\\\"\':[]&();-")) == 0) {
word.erase(0, 1);
}
return word;
}
string TrimTailPunc(string word) {
int index;
//remove any punctuations at tail of the word
while ((index = word.find_last_of(".,!?\\\"\':[]&();-")) == (word.length()
- 1)) {
word.erase(word.length() - 1, 1);
}
return word;
}
bool IsCapitalWord(string word) {
bool bCapital = true;
for (unsigned int i = 0; i < word.length(); i++) {
if (islower(word[i])) {
bCapital = false;
break;
}
}
return bCapital;
}
the problem is that i can not figure out how to make the program look for the excluded words in the set and skip them during the count. i was thinking of using the .find() and .erase commands for sets with a loop, but don't know to use it for the multiple words in the set.