Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. 2. 3. 4. C++ A space (' ') is a single character in C++. Just like 'a, 'A' , '5, or 96' in C++

1.image text in transcribed

2.image text in transcribed

3.image text in transcribed

4.image text in transcribed

C++

A space (' ') is a single character in C++. Just like 'a, 'A' , '5, or 96' in C++ Write a function that takes a sentence and returns the number of words in the sentence. Your function should take one parameter: o 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 Examples: "Go"-> 1 word "I went" ->2 words Colorless green ideas dream furiously -> 5 words "The rat the cat the dog bit chased escaped" 9 words You can assume that all words will be separated by single spaces in the sentence. Think about the relationship between the number of space characters and the number of words Edge cases: Make sure your function returns O if the string is empty (the length of the string is 0) . sentence = "" -> 0 words

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Students also viewed these Databases questions