STARTING OUT WITH C++FROM CONTROL STRU
STARTING OUT WITH C++FROM CONTROL STRU
18th Edition
ISBN: 9781323815458
Author: GADDIS
Publisher: PEARSON
Question
Book Icon
Chapter 10, Problem 3PC
Program Plan Intro

Word Counter

Program Plan:

  • Include the required header files to the program.
  • Define function prototype which is used in the program.
  • Define the “main()” function.
    • Declare the required variables.
    • Get the input c-string from the user and call the function “word_count”.
    • Print the c-string words count.
    • Get the input string object from the user and call the function “word_count”.
    • Print the string object words count.
  • Define the “word_count” function.
    • Declare the variable.
    • The “while” loop is used to count the number of words in that string.
      • The “while” loop is used to ignore the whitespaces.
      • The “if” condition is used to count the words.
      • The “while” loop is used to move to next word.
    • Finally return the words count to the main function.
  • Define the “word_count” function.
    • Declare the variable.
    • Get the length of the string.
    • The “for” loop is used to count the number of words in that string object.
      • The “if” condition is used to ignore the whitespaces. Otherwise it is used count the words.
      • The “if” condition is used to determine the words.
    • Finally return the words count to the main function.

Blurred answer
Students have asked these similar questions
Exercise 1: Word Separator Write a program that accepts as input a sentence in which all of the words are run together, but the first character of each word is uppercase. Convert the sentence to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example the string StopAndSmellTheRoses. would be converted to “Stop and smell the roses.” Exercise 2: replaceSubstring Function Write a function named replaceSubstring. The function should accept three string object arguments. Let’s call them string1, string2, and string3. It should search string1 for all occurrences of string2. When it finds an occurrence of string2, it should replace it with string3. For example, suppose the three arguments have the following values:   string1: “the dog jumped over the fence” string2: “the” string3: “that”   With these three arguments, the function would return a string object with the value “that dog jumped over that fence.” Demonstrate the…
(C++) 9.  True/False: the strcpy() function will make sure there is enough memory allocated in the destination string before copying C-strings     10.  True/False: when creating a string object, you must dynamically allocate enough bytes to hold the string     11.  Consider the following statement, assuming goAgain is a valid char.  Rewrite it using toupper() or tolower() if (goAgain == 'y' || goAgain == 'Y')     12.  Write a C++ function which accepts a pointer to a C-string as its argument.  It should return the number of words in the C-string.  For example, for the C-string “The Giants won the pennant!” your function should return 5.  You may assume the parameter passed is a pointer to a valid, null-terminated C-string with no newlines or tabs, exactly one space separates each word, and there is at least one word. int wordCounter(char* str)
def swap_text(text): Backstory: Luffy wants to organize a surprise party for his friend Zoro and he wants to send a message to his friends, but he wants to encrypt the message so that Zoro cannot easily read it. The message is encrypted by exchanging pairs of characters. Description: This function gets a text (string) and creates a new text by swapping each pair of characters, and returns a string with the modified text. For example, suppose the text has 6 characters, then it swaps the first with the second, the third with the fourth and the fifth with the sixth character. Parameters: text is a string (its length could be 0)Return value: A string that is generated by swapping pairs of characters. Note that if the Examples: swap_text ("hello") swap_text ("Party for Zoro!") swap_text ("") def which_day(numbers): → 'ehllo'→ 'aPtr yof roZor!' → '' length of the text is odd, the last character remains in the same position.

Chapter 10 Solutions

STARTING OUT WITH C++FROM CONTROL STRU

Ch. 10.5 - Write a short description of each of the following...Ch. 10.5 - Write a statement that will convert the string 10...Ch. 10.5 - Prob. 10.13CPCh. 10.5 - Write a statement that will convert the string...Ch. 10.5 - Write a statement that will convert the integer...Ch. 10.6 - Prob. 10.16CPCh. 10 - Prob. 1RQECh. 10 - Prob. 2RQECh. 10 - Prob. 3RQECh. 10 - Prob. 4RQECh. 10 - Prob. 5RQECh. 10 - Prob. 6RQECh. 10 - Prob. 7RQECh. 10 - Prob. 8RQECh. 10 - Prob. 9RQECh. 10 - Prob. 10RQECh. 10 - The __________ function returns true if the...Ch. 10 - Prob. 12RQECh. 10 - Prob. 13RQECh. 10 - The __________ function returns the lowercase...Ch. 10 - The _________ file must be included in a program...Ch. 10 - Prob. 16RQECh. 10 - Prob. 17RQECh. 10 - Prob. 18RQECh. 10 - Prob. 19RQECh. 10 - Prob. 20RQECh. 10 - Prob. 21RQECh. 10 - Prob. 22RQECh. 10 - Prob. 23RQECh. 10 - Prob. 24RQECh. 10 - The ________ function returns the value of a...Ch. 10 - Prob. 26RQECh. 10 - The following if statement determines whether...Ch. 10 - Assume input is a char array holding a C-string....Ch. 10 - Look at the following array definition: char...Ch. 10 - Prob. 30RQECh. 10 - Write a function that accepts a pointer to a...Ch. 10 - Prob. 32RQECh. 10 - Prob. 33RQECh. 10 - T F If touppers argument is already uppercase, it...Ch. 10 - T F If tolowers argument is already lowercase, it...Ch. 10 - T F The strlen function returns the size of the...Ch. 10 - Prob. 37RQECh. 10 - T F C-string-handling functions accept as...Ch. 10 - T F The strcat function checks to make sure the...Ch. 10 - Prob. 40RQECh. 10 - T F The strcpy function performs no bounds...Ch. 10 - T F There is no difference between 847 and 847.Ch. 10 - Prob. 43RQECh. 10 - char numeric[5]; int x = 123; numeri c = atoi(x);Ch. 10 - char string1[] = "Billy"; char string2[] = " Bob...Ch. 10 - Prob. 46RQECh. 10 - Prob. 1PCCh. 10 - Prob. 2PCCh. 10 - Prob. 3PCCh. 10 - Average Number of Letters Modify the program you...Ch. 10 - Prob. 5PCCh. 10 - Prob. 6PCCh. 10 - Name Arranger Write a program that asks for the...Ch. 10 - Prob. 8PCCh. 10 - Prob. 9PCCh. 10 - Prob. 10PCCh. 10 - Prob. 11PCCh. 10 - Password Verifier Imagine you are developing a...Ch. 10 - Prob. 13PCCh. 10 - Word Separator Write a program that accepts as...Ch. 10 - Character Analysis If you have downloaded this...Ch. 10 - Prob. 16PCCh. 10 - Prob. 17PCCh. 10 - Prob. 18PCCh. 10 - Check Writer Write a program that displays a...
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning