Question: I am trying to write code for this problem but I keep getting the wrong numbers for some of the tests. I have: int countWord(string

 I am trying to write code for this problem but I

I am trying to write code for this problem but I keep getting the wrong numbers for some of the tests.

keep getting the wrong numbers for some of the tests. I have:

I have:

int countWord(string str, string match){

int count = 0;

size_t nPos = str.find(match, 0); // fist occurrence

while(nPos != string::npos){

count++;

nPos = str.find(match, nPos+1);

}

return count;

}

PLEASE HELP!

Now that we are able to standardize strings to some extent by removing punctuation and converting to lowercase we want to be able to count the number of occurrences of a given substring or word within a larger string. Write the function countWord which returns an int and takes two strings as arguments. The first argument is a full sentence and the second is the substring or word that we are interested in. Remember, you may use the function lowerNoPunctuation from the previous question. Copy your code from the previous problem into this problem int countWord (string sentence, string word) //Your code here This function should follow the pseudocode: int countWord (sentence, matchWord) while there are words in the sentence strip off punct, make all lower case if wordmatchWord ++count return count Example Output: string punctuation - ".,!$*&^%$():-"; int sellsCount countword("She sells sea-shells on the sea-shore. The shells she sells are sea-shells, cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!