Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ The filter words counts the number of words in input as long as each word is separated from the next by one or

IN C++

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

The filter words counts the number of words in input as long as each word is separated from the next by one or more spaces. Modify the program so that it makes explicit tests for the space, tab and newline characters. Make sure it also counts the last word in a line which doesn't end in a newline. Complete the following file: words.cpp 1 2 #include using namespace std; /** 3 4 5 6 7 8 9 10 11 12 13 14 15 16 A state filter which counts words that are separated by spaces. */ int main() { bool in AWord{false}; // haven't read anything yet int words{0}; // so we have no words char ch; while (cin.get(ch)) { if (ch '') // any whitespace character 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 if (ch == ') // any whitespace character { if (inAWord) // transition leaving a word { inAword = false; words++; } } else { inAword = true; } } cout

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

Recommended Textbook for

Records And Database Management

Authors: Jeffrey R Stewart Ed D, Judith S Greene, Judith A Hickey

4th Edition

0070614741, 9780070614741

More Books

Students also viewed these Databases questions