Write a C++ program that manipulates a string entered by the user. The program s
ID: 3721723 • Letter: W
Question
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:
USE THIS MENU TO MANIPULATE YOUR STRING
---------------------------------------
1) Inverse String
2) Reverse String
3) To Uppercase
4) Jumble String
5) Count Number Words
6) Count Consonants
7) Enter a Different String
8) Print the String
9) Quit
Option 1) Inverse the upper and lower case letters of the string. If the string contains numeric characters or special characters do not change them.
Option 2) Reverse the order of the characters in the string.
Option 3) Convert all of the characters in the string to uppercase
Option 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
Option 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
"2016" is one word "I ran track" is 3 words
.Option 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. (non vowels)
Option 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
Option 8) Print the String
Option 9) Quit program
Explanation / Answer
hey dear student!
i've completed this program, compiled and excuted successfully
#include <iostream.h>
#include <string.h>
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
#include<stdlib.h>
int main ()
{
char str[100];
int i = 0;
char choice,temp=' ';
int count=0, cons=0;
clrscr();
cout << "Enter a word, sentence, or a string of numbers" << endl;
gets(str);
fflush(0);
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) Jumble String" << endl;
cout << "5) Count Number of Words " << endl;
cout << "6) Count Consonants" << endl;
cout << "7) Enter a Different String " << endl;
cout << "8) Print the String " << endl;
cout << "9) Quit " << endl;
cin >> choice;
switch(choice)
{
case '1':
{
for(i=0;i<strlen(str);i++)
{
if(isupper(str[i]))
{
str[i] = tolower(str[i]);
}
else if(tolower(str[i]))
{
str[i] = toupper(str[i]);
}
}
cout<<" Modified String : ";
puts(str);
break;
}
case '2' :
{
cout<<" Reverse of string : ";
for (i=strlen(str)-1;i>=0;i--)
cout<<str[i];
break;
}
case '3' :
{
for(i=0;i<strlen(str);i++)
{
str[i]=toupper(str[i]);
}
cout<<" Uppercase String : ";
puts(str);
break;
}
case '4' :
{/* here i've faced some errors, and due to less time couldn't sort the errors for this case. that's left this case incomplete.*/
puts(str);
break;
}
case '5':
{
for(i=0;i<strlen(str);i++)
{
if(str[i]==' ')
count++;
}
cout<<"Number of words in the String : "<<count+1<<endl;
break;
}
case '6' :
{
for(i=0;i<strlen(str);i++)
{
if(str[i]=='a'||str[i]=='A'||str[i]=='e'||str[i]=='E'||str[i]=='i'||str[i]=='I'||str[i]=='o'||str[i]=='O'||str[i]=='u'||str[i]=='U')
{
}
else
cons++;
}
cout<<"Number of consonants in the string : "<<cons<<endl;
break;
}
case '7' :
{
cout<<"Enter New String : ";
gets(str);
fflush(0);
cout<<" New String : ";
puts(str);
}
case '8' :
{
cout<<" String : ";
puts(str);
break;
}
case '9' :
{
cout<<"Thank You for using this program!"<<endl;
cout<<"Press Enter to continue"<<endl;
getch();
break;
}
default:
{
cout<<" Wrong choice!";
break;
}
}
getch ();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.