Question
String Processing Program **IMPORTANT!!: Note you must use the string operators and CHRACTER functions to solve this problem (examples: the subscript operator and the isupper
String Processing Program
**IMPORTANT!!: Note you must use the string operators and CHRACTER functions to solve this problem (examples: the subscript operator and the isupper function). Do not use library functions in cases where you can solve the problem based on what we learned in lecture.
Write a c++ program that manipulates a string entered by the user.
The program should start by asking the user to enter a word, a sentence, or a string of numbers. Store whatever the user enters into a C++ string.
The program should then display the following menu (you must use 'Q' for quit):
USE THIS MENU TO MANIPULATE YOUR STRING
----------------------------------------
1) Inverse String
2) Reverse String
3) To Uppercase
4) Count Number Words
5) Count Consonants
6) Enter a Different String
7) Print the String
Q) Quit
If the user selects 1: Inverse the upper and lower case letters of the string. If the string contains numeric characters or special characters do not change them. NOTE: This option should actually change the string to its inverse. Note this option does not display the changed string. If a user wanted to inverse the string and then display the string's inverse they would select option 1 and then they would select option 7.
Example: If the string is: My name is John and I am 20 years old.
The inverse would be: mY NAME IS jOHN AND i AM 20 YEARS OLD.
If the user selects 2: Reverse the order of the characters in the string. NOTE: This option should actually change the string to its reverse - do NOT just copy the slides from class, you need to modify it. Note this option does not display the changed string. If a user wanted to reverse the string and then display the string's reverse they would select option 2 and then they would select option 7.
Example: If the string is: 2015
The inverse would be: 5102
If the user selects 3: Convert all of the characters in the string to uppercase. If the String contains numeric characters or special characters do not change them. NOTE: This option should actually change the string to all uppercase letters. Note this option does not display the changed string. If a user wanted to change the string to uppercase and then display the new string (in all uppercase) they would select option 3 and then they would select option 7.
If the user selects 4: Call a function named countWords that counts the number of words in the current string and displays a message stating how many words are in the string. This option actually should print something.
Examples: The string "2015" has one word
The string "Hello World" has two words
If the user selects 5: Call a function named countConsonants that counts the number of consonants in the current string and displays a message indicating how many consonants the string contains. So this option does print something. Consonants are letters that aren't vowels (anything EXCEPT a, e, i, o, u).
Example: If the string is: Hello
The number of consonants is: 3
So display: "The number of consonants in the string is 3."
If the user selects 6: Let the user enter another string for processing. (This should just change the string stored in the original string variable you created at the beginning of the program)
If the user selects 7: Print the String
o So if the original string was "Hello" and the user processed the string with option 3 followed by option 2, followed by option 8, the string would print out as "OLLEH" (This is hello first converted to uppercase and then reversed).
If the user selects Q or q: Quit the program
Allow the user to continue processing strings (using the menu) until they select Q or q to quit
If the user makes an invalid menu selection, print an error message to the screen
Your program must include the following two functions (you can include more if you want):
1. countWords: A function that takes a string as an argument and counts the number of words in it (this function should return an int which is the number of words in the string)
2. countConsonants: A function that takes a string as an argument and counts the number of consonants in it (this function should return an int which is the number of consonants in the string)
View required output
Test Case 1
Standard Input |
---|
This is C++ Class on WEDNESDAY NightsENTER 1ENTER 2ENTER 7ENTER 6ENTER WHAT is THIS?ENTER 3ENTER 7ENTER 9ENTER 9ENTER Q |
Please enter a word, a sentence, or a string of numbers. USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit The current string is: STHGIn yadsendew NO SSALc ++c SI SIHt USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit Enter a different string : USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit The current string is: WHAT IS THIS? USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit Invalid selection. Please try again. USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit Invalid selection. Please try again. USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit You have chosen to quit the program. Thank you!
Test Case 2
Standard Input |
---|
Spring Break is coming soon!!!ENTER 4ENTER 5ENTER 3ENTER Q |
Please enter a word, a sentence, or a string of numbers. USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit The string "Spring Break is coming soon!!!" has 5 word(s) USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit The number of consonants in the string is 15. USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit You have chosen to quit the program. Thank you!
Test Case 3
Standard Input |
---|
There are two spaces between each wordENTER 4ENTER q |
Please enter a word, a sentence, or a string of numbers. USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit The string "There are two spaces between each word" has 7 word(s) USE THIS MENU TO MANIPULATE YOUR STRING --------------------------------------- 1) Inverse String 2) Reverse String 3) To Uppercase 4) Count Number Words 5) Count Consonants 6) Enter a Different String 7) Print the string Q) Quit You have chosen to quit the program. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started