Question
Please use C++ programing. Functions Write the following functions. Each of these functions should have a single parameter -- accepting a c-style string as an
Please use C++ programing.
Functions
Write the following functions. Each of these functions should have a single parameter -- accepting a c-style string as an argument. The function should only do what is specified (note that none of these functions do any output to the screen). Your functions should use const in the prototype wherever it is appropriate:
-
Write a function that counts and returns the number of vowels in the string. (For the purposes of this exercise, we are talking about the standard 5 vowels -- A, E, I, O, U).
-
Write a function that counts and returns the number of consonants in the string.
-
Write a function that converts the string to all lowercase.
-
Write a function that converts the string to all uppercase.
NOTE: You should not use the string class anywhere in your program. You may only use cstrings. Do not use the strlen function.
Menu program
Write a main program that performs the following steps:
-
Prompt the user to enter a string, and let them type it in. This could be an entire sentence, with the newline indicating the end of the string. You may assume the string will be no more than 100 characters, so declare your array accordingly. (Note: the functions should still work for arrays larger than 100 characters).
-
Display the following menu:
-
A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string F) Enter another string M) Display this menu X) Exit the program
-
Enter a loop, allowing the user to type in a menu choice each time. Loop should continue until the user enters the command to exit. Upper and lowercase letters should be allowed for the menu choices.
-
When the A or B commands are entered (counting vowels or consonants), call the corresponding function, then print the result
-
When the C or D commands are chosen, just call the appropriate function to convert the string. Do not do any output from main on these commands.
-
When E is chosen, print the contents of the stored string.
-
When F is chosen, allow a new string to be typed -- this will replace the previous one.
-
The menu should only be displayed once at the start, and then again whenever the M option is selected
-
Sample Run
(user input is underlined, to distinguish it from output)
Input a line of text, up to 100 characters: > The quick brown fox jumped. The lazy dog, he was jumped over. A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string F) Enter another string M) Display this menu X) Exit the program Enter your menu selection: a Number of vowels: 16 Enter your menu selection: B Number of consonants: 31 Enter your menu selection: c Enter your menu selection: e The string: THE QUICK BROWN FOX JUMPED. THE LAZY DOG, HE WAS JUMPED OVER. Enter your menu selection: D Enter your menu selection: E The string: the quick brown fox jumped. the lazy dog, he was jumped over. Enter your menu selection: f Input a new line of text, up to 100 characters: > Mary Had A Little Lamb. His name was Fleecy Pete. Enter your menu selection: C Enter your menu selection: e The string: MARY HAD A LITTLE LAMB. HIS NAME WAS FLEECY PETE. Enter your menu selection: d Enter your menu selection: E The string: mary had a little lamb. his name was fleecy pete. Enter your menu selection: b Number of consonants: 24 Enter your menu selection: a Number of vowels: 14 Enter your menu selection: x Goodbye
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