Please provide answer in the format that I provided, thank you
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.
You must insert the following comments at the beginning of your program and write our commands in the middle:
Write a C++ Program:
/*
// Name: Your Name
// ID: Your ID
// Purpose Statement:~~~
*/
#include <iostream>
#include <string>
using namespace std;
void removeVowels(string& str);
bool isVowel(char ch);
int main()
{
string str;
cout << "Enter a string: ";
…
…
YOUR CODE HERE
…
…
return 0;
}
void removeVowels(string& str)
{
int len = str.length();
…
…
YOUR CODE HERE
…
…
}
bool isVowel(char ch)
{
switch (ch)
…
…
YOUR CODE HERE
…
…
}
#include <iostream>
#include <string>
using namespace std;
void removeVowels(string &str);
bool isVowel(char ch);
int main()
{
string str;
cout << "Enter a string: ";
// YOUR CODE HERE
cin >> str;
// remove all vowels
removeVowels(str);
cout << "String after removing vowels: " << str;
return 0;
}
void removeVowels(string &str)
{
int len = str.length();
// YOUR CODE HERE
int i = 0;
while (i < len)
{
// if current char is vowel
if (isVowel(str[i]))
{
// remove char
str = str.substr(0, i) + str.substr(i + 1, len);
len = str.length();
}
else
i++;
}
}
bool isVowel(char ch)
{
switch (ch)
{
// YOUR CODE HERE
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;
}
}
.
Output:
.
Get Answers For Free
Most questions answered within 1 hours.