Write a program that prompts the user to input a string. The program then uses t
ID: 3686202 • Letter: W
Question
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. Grading scheme: a function to remove all vowels: 5 points; a function to determine whether a character is vowel: 5 points; a main function and correct output for any string: 10 points.Explanation / Answer
#include <iostream>
#include <string>
using namespace std;
void findVowels(string newWord);
string removeVowel(string word, int position);
int main()
{
string originalWord;
int count = 0;
string letter;
char ch;
cout << "Enter a word: ";
cin >> originalWord;
cout << endl;
string newWord = originalWord;
findVowels(newWord);
return 0;
}
void findVowels(string word)
{
string vowels = 'aeiouAEIOU'
string Word = word;
for(int i = 0;i< vowels.length;i++)
{
int position = Word.find(vowels.at(i),0);
if (position > 0)
{
Word = removeVowel(word,position);
}
}
cout << "After removing vowels new word is: " << Word;
}
string removeVowel(string word, int position)
{
return word.erase(position);
}