Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

ATTENTION!!!: This assignment is for a basic and introductory C++ course. As suc

ID: 3836506 • Letter: A

Question

ATTENTION!!!: This assignment is for a basic and introductory C++ course. As such, please do not use complex or obscure opperations and headers that would typically be used in advanced classes as we have not learned them yet. Use only very simple functions and headers. If you are unsure of whether a technique is too advanced, dont use it. If you can answer the question without using a function, please do so.

"C type" string is implied to mean an array of characters with an end of string mark following the last character.

Write a function named WordCount, which determines the number of words in a "C type" string. The function will have one parameter (the address of the string) and will return the number of words (words are seperated by one or more spaces).

Explanation / Answer

Here is the code for you:

int wordCount(char* words)
{
    int count = 1;
    int i = 0;
    while(words[i] != '')
    {
       if(words[i] == ' ' && words[i-1] != ' ')
           count++;
       i++;  
    }
    return count;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote