Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that prompts the user to input a string. The program then to rem

ID: 3927084 • Letter: W

Question

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.

Explanation / Answer

// 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

*/

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote