Hey guys, heres the instructions for my homework:
1. 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.
2. 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. 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
here's the code I have so far
the question I have is:Code:#include <iostream> #include <string> #include <cctype> #include <iomanip> using namespace std; int countWords(string); int main () { string str; int i = 0; char choice; cout << "Enter a word, sentence, or a string of numbers" << endl; getline(cin, str); cout << "USE THIS MENU TO MANIPULATE YOUR STRING" << endl; cout << "---------------------------------------" << endl; cout << "1) Inverse String " << endl; cout << "2) Reverse String " << endl; cout << "3) To Uppercase " << endl; cout << "4) Count Number Words " << endl; cout << "5) Count Consonants " << endl; cout << "6) Enter a Different String " << endl; cout << "7) Print the String " << endl; cout << "Q) Quit " << endl; cin >> choice; if(choice == '1') { for( i = 0; i < str.length(); i++) { if(isupper(str[i])) { str[i] = tolower(str[i]); } else if(tolower(str[i])) { str[i] = toupper(str[i]); } } str = str[1]; } if(choice == '2') { for (i = str.length()-1; i >= 0; i--) { str = str[i]; } } if(choice == '3') { for(i = 0; i < str.length(); i++) { if(tolower(str[i])) { str[i] = toupper(str[i]); } } cout << str <<endl; } if(choice == '4) { countWords( system("PAUSE"); return 0; }
1)how do I get it so it displays the new string whenever i press 7?
2)how would I construct the fuction countWords and countConsonants?
3)and in order for the menu reptition I would have to create a do while statement right? i would much appreciate a basic template, such as
do
menu
if
statement
if
statement
something basic like that
I understand if the questions may seem too demeaning or me being lazy on my part, but I seriously suck at programming as my skills in word problems and basic problem solving seriously SUCKS.
Thanks in advance