Write a program that prompts the user to input a string The
Write a program that prompts the user to input a string. The program then 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 that returns the a string with the vowels removed and a function to returns whether or not a single character is a vowel. Hint: The substr function might be useful, but you may find a simple solution that instead uses string concatenation and the array subscript operator.
Solution
// C++ code delete vowels from string
#include <iostream>
#include <string.h>
using namespace std;
// check id character is vowel
bool checkVowels(char ch)
{
switch(ch)
{
case \'a\':
case \'A\':
case \'e\':
case \'E\':
case \'i\':
case \'I\':
case \'o\':
case \'O\':
case \'u\':
case \'U\':
return true;
default:
return false;
}
}
string deleteVowels(string s)
{
for (int i = 0; i < s.length(); i++)
{
if (checkVowels(s[i]) == true)
{
// check for vowel and remove the character
memmove(&s[i], &s[i + 1], s.size() - i);
}
}
return s;
}
int main()
{
string str;
cout << \"Enter string: \";
getline(cin ,str);
cout << \"\ Result: \" << deleteVowels(str) << endl;
return 0;
}
/*
output:
Enter string: fernsandpetals
Result: frnsndptls
*/

