Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Identify five strategies to prevent workplace bullying.

Answered: 1 week ago