Question & Answer: The program should start by asking the user to enter a word, a sentence, or a string of numbers. Store whatever the u…..

Write a 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:
USE THIS MENU TO MANIPULATE YOUR STRING
—————————————-
1) Inverse String
2) Reverse String
3) To Uppercase
4) Jumble String 4-1 Sample Run
5) Count Number Words
6) Count Consonants
7) Enter a Different String
8) 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 8.
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. 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 8.
Example: If the string is: 2015
The reverse 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 8.
¨ If the user selects 4:– Call a function named jumbleString. The jumbleString function takes a string as input and displays a jumbled version of that string. The jumbleString function should be called using current version of the string an argument (input) to the function.
Example: If the string passed to the jumbleString function is: hello
A jumbled version of the word would be: elhlo
Note 1: there are many different jumbled versions of each word that the jumbleString function could display. So elhlo is not the only correct output for the above example.
Note 2: Notice that this option does not actually change the string like the first two menu selections do, the jumbleString function just displays a jumbled version of the string rather than actually changing the string
¨ If the user selects 5: 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
Examples: The string “2015” has one word
The string “Hello World” has two words
The string “ I am Woman ” has 3 words
¨ If the user selects 6: 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. Consonants are letters that aren’t vowels.
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 7: 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 8: 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 three 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)
3. jumbleString: A function that take a string as an argument and displays a jumbled version of the original string.

Expert Answer

 

/*The source code is given below:*/

Don't use plagiarized sources. Get Your Custom Essay on
Question & Answer: The program should start by asking the user to enter a word, a sentence, or a string of numbers. Store whatever the u…..
GET AN ESSAY WRITTEN FOR YOU FROM AS LOW AS $13/PAGE
Order Essay

#include <iostream>

#include<cstring>

#include<algorithm>

using namespace std;

void jumbleString(string s);

void countWords(string s);

void countConsonants(string str);

int main()

{

char option; // user’s entered option will be saved in this variable

string myStr;//user’s entered string will be saved in this variable

cout<<endl<<“Enter input string: “;

getline(cin,myStr);

do //do-while loop displays menu again and again until user select to exit

{

//Displaying Options for the menu

cout<<endl<<“===========Menu============”<<endl;

cout << “1) Inverse String” << endl;

cout << “2) Reverse String ” << endl;

cout << “3) To Uppercase” << endl;

cout << “4) Jumble String ” << endl;

cout << “5) Count Number Words ” << endl;

cout << “6) Count Consonants ” << endl;

cout << “7) Enter a Different String ” << endl;

cout << “8) Print the String ” << endl;

cout << “Q) Quit ” << endl;

//Prompting user to enter an option according to menu

cout << “Please select an option : “;

cin>>option; // taking option value as input and saving in variable “option”

if(option == ‘1’) // Checking if user selected option 1

{

//inversing string

for(int i=0;i<myStr.length();i++)

{

if(isupper(myStr[i]))

myStr[i]=tolower(myStr[i]);

else if(islower(myStr[i]))

myStr[i]=toupper(myStr[i]);

else

continue;

}

}

else if(option == ‘2’) // Checking if user selected option 2

{

//reversing the string

reverse(myStr.begin(),myStr.end() );

}

else if(option == ‘3’) // Checking if user selected option 3

{

//converting all letters to uppercase

for(int i=0;i<myStr.length();i++)

{

if(isupper(myStr[i]))

continue;

else if(islower(myStr[i]))

myStr[i]=toupper(myStr[i]);

else

continue;

}

}

else if(option == ‘4’) // Checking if user selected option 4

{

//calling a function to display jumbled version of the input string

jumbleString(myStr);

}

else if(option == ‘5’) // Checking if user selected option 5

{

//calling a function to display number of words in the input string

countWords(myStr);

}

else if(option == ‘6’) // Checking if user selected option 6

{

//calling a function to display number of consonants in the input string

countConsonants(myStr);

}

else if(option == ‘7’) // Checking if user selected option 7

{

//let the user enter another string for processing

cin.clear();cin.ignore(INT_MAX,’n’);//flush out cin buffer

cout<<endl<<“Enter another input string: “<<endl;

getline(cin,myStr);

}

else if(option == ‘8’) // Checking if user selected option 3

{

//displaying the string

cout << endl<<myStr<< endl;

}

else if((option == ‘Q’) || (option==’q’) )// Checking if user selected option q or Q

{

cout << “Thank you!!” << endl;

}

else //if user has entered invalid choice (other than 1 to 8 ,q, Q)

{

//Displaying error message

cout << “Invalid Option entered!!” << endl;

}

}while((option != ‘q’) && (option != ‘Q’ )); //condition of do-while loop

return 0;

}

void jumbleString(string s)

{

string str=s;

random_shuffle(str.begin(), str.end());

cout <<endl<< str << endl;

}

void countWords(string str)

{

int words = 0; // Holds number of words

for(int i = 0; i<str.length(); i++)

{

if (str[i] == ‘ ‘) //Checking for spaces

{

words++;

}

}

cout << “The string “”<<str<<“” has “;

if(words+1 == 1)

cout<<words+1<<” word”<<endl;

else

cout<<words+1<<” words”<<endl;

}

void countConsonants(string str)

{

int cons = 0; // Holds number of consonants

for(int i = 0; i<str.length(); i++)

{

char ch = str[i];

if (isalpha(str[i])) //Checking for alphabet

{

if(ch==’a’ || ch==’A’ || ch==’e’ || ch==’E’ ||

ch==’i’ || ch==’I’ || ch==’o’ || ch==’O’ ||

ch==’u’ || ch==’U’)

{

continue;

}

else

{

cons++;

}

}

}

cout << “The number of consonants in the string is “<<cons<<endl;

}

/*For better understanding output screenshot is attached here*/

Grand Paper Writers
Order NOW For A 10% Discount!
Pages (550 words)
Approximate price: -

Our Advantages

Plagiarism Free Papers

All papers are written by the best professional writers to ensure 100% originality. We always provide plagiarism reports whenever we deliver completed papers.

Free Revisions

All papers by Grand Paper Writers are completed and submitted on time. This timely delivery of papers gives you time to go through the paper before the official deadline.

Title-page

As an additional service, we will provide a title page that precedes the contents of your paper. Here, you will provide your personal details.

Bibliography

We also ensure that we provide an extra page for the references or bibliographies following referencing rules.

Originality & Security

At Grandpaperwriters.com, we guarantee students for the provision of security and original work. All your personal information is handled with confidentiality and is not shared with third parties. Additionally, we ensure that we provide original content with accompanying plagiarism reports to show originality.

24/7 Customer Support

Our customer support team is always available 24/7 to provide instant responses to any queries raised by students.

Try it now!

Calculate the price of your order

We'll send you the first draft for approval by at
Total price:
$0.00

How it works?

Follow these simple steps to get your paper done

Place your order

Fill in the order form and provide all details of your assignment.

Proceed with the payment

Choose the payment system that suits you most.

Receive the final file

Once your paper is ready, we will email it to you.

Our Services

Grandpaperwriters.com has the best professional essay writers for quality services.

Pricing

Flexible Pricing

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Communication

Admission Help & Client-Writer Contact

Grandpaperwriters.com provides an interactive portal where students can communicate directly to their writers.

Deadlines

Paper Submission

Here, a Grandpaperwriters.com, we do not compromise on the time of our clients. We always deliver all completed papers on or before the deadlines.

Reviews

Customer Feedback

Grandpaperwriters.com appreciates feedback from our clients to help us improve the delivery of essay writing services. As such, we are constantly changing our policies to ensure maximum customer and writer satisfaction.