C++ – No Vowels Problem: Find a way to remove vowels and certain other groups of
ID: 3669805 • Letter: C
Question
C++ – No Vowels
Problem: Find a way to remove vowels and certain other groups of characters from a string.
Your assignment: Write and test a C++ program that prompts the user to input a string. The program then uses a user-defined function to remove all the vowels from the string. Do not replace the vowels with any other character. For example, if str = “There”, then after removing all the vowels, str = “Thr”. After removing all the vowels, output the string.
Discussion: Removing characters from a string involves two operations: 1) recognizing which characters in the string fall within the group being removed, and 2) removing those characters from the string. Consider the following steps to accomplish these tasks. Develop a function that accepts a string, iterates through the characters in the string, and removes each character that is a member of the group known as “vowels”. The function should return an edited version of the original string. Write a main program that reads a string of one or more words from the console, uses the userdefined function (described above) to remove all the vowels from the input string, and then displays the input string and vowel-less result string. Repeat till the user opts to quit.
Coding Accept any sequence of characters, including embedded spaces from the input. Your program must contain at least one function to remove the vowels from a string. Validate all inputs and do not proceed until valid inputs are available. For the purposes of this assignment, vowels include only the letters a, e, I, o, and u in both upper case and lower case. Format your source code according to the style guide presented in class.
Bonus Allow the user to specify one of the following groups of characters to remove from the input string: vowels, consonants, digits, and punctuation. Allow the user to specify a group of user-selected characters to remove from the input string. This option must not be included without the previous bonus feature.
Explanation / Answer
This below C++ code is implemented removing the vowels from the given string using function.
1. Created method called removeVowels which will remove the voewls and retuen the number vowels are removed from the strng..
See the below code:
#include <iostream>
using namespace std;
int removeVowles(string text)
{
int count = 0, j=0;
char text2[100];
for (int i=0,j=0;text[i]!='';i++) {
if (text[i]=='a' || text[i]=='e' || text[i]=='i' || text[i]=='o' || text[i]=='u' || text[i]=='A' || text[i]=='E' || text[i]=='I' || text[i]=='O' || text[i]=='U')
{
//text2[j]=text[i];
//j++;
}
else
{
text2[j]=text[i];
j++;
count++;
}
}
cout <<"After Removong Ovels from the String is :"<< text2<<endl;;
return count;
}
int main()
{
string text;
cout << "Insert the string" << endl;
cin >> text;
cout<<"Number of Ovewls are Removed :"<<removeVowles(text)<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.