Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ simple programming style no pointers no arrays Write a C++ program, named count.cpp, that counts and reports the number of words in a line

c++ simple programming style no pointers
no arrays image text in transcribed
image text in transcribed
Write a C++ program, named "count.cpp", that counts and reports the number of words in a line of text entered by the user. There are a few special notes about the program: Your program should have a value returning function named "Count Words" that takes as input a string type parameter, and returns the number of words in the string as the function's return value. The user may enter an empty line of text, i.e., just press enter when prompted. Your program should report 0 words in this case. There may be one or more white spaces in between pairs of words. Your program should skip over these white spaces in thtt case. You are required to use C++ string functions in developing this program. Here are a few example runs of the program: Sample run 1: Please enter a line of text: The baby smiles as soon as she wakes up. There are 9 words in this sentence. Sample run 2: Please enter a line of text: Tom and Jerry are lovely characters. There are 6 words in this sentence. Sample run 3: Please enter a line of text: There is O word in this sentence. Bonus (5 pts) In addition to counting the number of words in the sentence, find and display the number of occurrences of the word "the" in the sentence, for example: Sample run 4: Please enter a line of text: The amount of attention received by the article is astonishing. There are 10 words in the sentence. The word occurred 2 times in the sentence. Sample run 5: Please enter a line of text: Tom and Jerry are lovely characters. There are 6 words in this sentence. The word occurred 0 times in the sentence. There may be one or more white spaces in between pairs of words. Your program should skip over these white spaces in thit case. You are required to use C++ string functions in developing this program Here are a few example runs of the program: Sample run 1: Please enter a line of text: The baby smiles as soon as she wakes up. There are 9 words in this sentence. Sample run 2: Please enter a line of text: Tom and Jerry are lovely characters. There are 6 words in this sentence. Sample run 3: Please enter a line of text: There is O word in this sentence. Bonus (5 pts) In addition to counting the number of words in the sentence, find and display the number of occurrences of the word "the" in the sentence, for example: Sample run 4: Please enter a line of text: The amount of attention received by the article is astonishing. There are 10 words in the sentence. The word occurred 2 times in the sentence. Sample run 5: Please enter a line of text: Tom and Jerry are lovely characters. There are 6 words in this sentence. The word occurred 0 times in the sentence. Your program should be written in such a way that the word to look for can be easily switched to another word. That is, do not hard code the program to look for the specific word "the". Use a variable named "wordToCount" of string type, and search for this word in the sentence

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

Logic In Databases International Workshop Lid 96 San Miniato Italy July 1 2 1996 Proceedings Lncs 1154

Authors: Dino Pedreschi ,Carlo Zaniolo

1st Edition

3540618147, 978-3540618140

More Books

Students also viewed these Databases questions