Removing vowels from string – CSKC
Sign In

Search

Solved Problem #CPP#2628    siteicon   siteicon  

Problem Statement - Removing vowels from string

Write a program to collect input sentence from user into a character array as a null terminated string. Reprint the user given sentence after removing all the vowels. You can use switch case or if-else to check the vowel condition.

Solution

TC++ #2628

 

×

Ask AI About This Code

Default Prompt that is passed along with the code is given below, You can write your own prompt if you so desire.



×

Test CPP

  Related ( ? ) :

char str[100]; cout<<“Input a sentence:” ; cin.getline(str,100);
Here we collect the string input from the user. The null termination is automatically done by cin.getline()

for(int i=0;str[i]!=”;i++) //Whole string is traversed from 0th index to the position just before the null () character.
{
switch(str[i]) {  //Switch for each character in the string is applied

case ‘a’:case ‘A’: case ‘e’: case ‘E’:
case ‘i’:case ‘I’: case ‘o’: case ‘O’:
case ‘u’:case ‘U’: break; 
All types of upper and lowercase vowels are checked and if vowel is found break from switch is done. Which means nothing is printed.

default: cout<<str[i]; //In all other cases other than the vowels the current character is printed.
}  //This is switch end
} //This is loop end

Finally the sentence without the vowels come on the screen.

 

Notes

  • Vowel removal is a popular method of abbreviating messages. One can convey the messages between two ends after vowel removal and the message can still be understood by the humans.

Common Errors

  • If break after the vowel cases are missed then the full sentence will be printed as it is. Care must be taken to ensure its presence.


Share

Created: 14-Jan-2018 22:12 | Updated: 14-Jan-2018 22:25|