Question: (C++) A space (' ') is a single character in C++, just like 'a', 'A' , '5', and '%' (for example). In English, a space
(C++) A space (' ') is a single character in C++, just like 'a', 'A' , '5', and '%' (for example). In English, a space is used to separate individual words. Write a function that takes an English sentence and returns the number of words in the sentence.
Your function should take one parameter: a string parameter for the sentence
Your function should return the number of words in the sentence.
Your function should not print anything.
Your function MUST be named getWordCount.
Note: You can assume there is exactly one single space between any two words.
Examples:
Input parameter: " " (an empty string) return 0;
Input parameter: "Go" return 1;
Input parameter: "I went" return 2;
Input parameter: "Colorless green ideas dream furiously" return 5;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
