32.8k views
3 votes
Write a program that prompts the user to input a string.

The program then uses the function substr to remove all the vowels from the string.


For example, if str = "There", then after removing all the vowels, str = "Thr".


After removing all the vowels, output the string.


Your program must contain a function to remove all the vowels and a function to determine whether a character is a vowel.

User Fenollp
by
5.6k points

1 Answer

3 votes

Answer:

#include <iostream>

using namespace std;

bool is_vowel(char c)

{

switch(c) //switch case to check if vowel is present

{

case 'a':

case 'A':

case 'e':

case 'E':

case 'i':

case 'I':

case 'o':

case 'O':

case 'u':

case 'U': return true;

break;

default : return false;

}

}

string remove_vowel(string input)

{

string str="";

for(int i=0;input[i]!='\0';i++)

{

if(!is_vowel(input[i])) //if vowel then not copied to substring

str+=input[i];

}

return str;

}

int main()

{

string str;

cout<<"Enter string\\";

cin>>str;

cout<<"\\After removal of vowels substring is : "<<remove_vowel(str); //substring is returned

return 0;

}

OUTPUT :

Enter String

There

After removal of vowels substring is : Thr

Step-by-step explanation:

The above program contains two methods in which one is is_vowel() which checks if the passed character is a vowel or not and the other method is remove_vowel() which removes all vowels from the string and returns a string which does not contain any vowel. This method passes every character of the string to the is_vowel() method and if false then it copies the character to the new string. At last, it returns a new string.

User Jay Shah
by
5.1k points