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

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!