Write a C++ program that prompts the user to input a string. The program then us
ID: 3620135 • Letter: W
Question
Write a C++ 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", the function would remove the 2 e's and output "Thr". Your program needs to contain a main routine, and a function to remove all the vowels, and a function to determine whether a character is a vowel.This is what I have so far!
[code]
#include <iostream>
#include <string>
using namespace std;
int main()
{
string word;
cout << "Enter a sting" << endl;
getline (cin,word);
for(int i=0; i<word.length(); i++)
{
if(name[i] == "a,e,i,o,u")
string sub = [i]
}
cout << string
char any_keystroke;
//reads and ignores up to 200 characters, or ' ' is read and ignored
cin.ignore(200, ' ');
cout << " ";
cout << "Program execution has ended normally. ";
cout << "Press the enter key to exit.";
cin.get(any_keystroke);
return 0;
}
[/code]
Explanation / Answer
please rate - thanks #include <iostream>#include <string>
using namespace std;
string removevowels(string&);
bool isvowel(char);
int main()
{
string word;
cout << "Enter a string" << endl;
getline (cin,word);
cout<<"with vowels: "<<word<<endl;
word=removevowels(word);
cout<<"without vowels: "<<word<<endl;
char any_keystroke;//reads and ignores up to 200 characters, or ' ' is read and ignored
cin.ignore(200, ' ');
cout << " ";
cout << "Program execution has ended normally. ";
cout << "Press the enter key to exit.";
cin.get(any_keystroke);
return 0;
}
string removevowels(string& word )
{int i,prev=0;
string result="";
for(i=0;word[i]!='';i++)
if(isvowel(word[i]))
{result=result+word.substr(prev,i-prev);
prev=i+1;
}
result=result+word.substr(prev,i-prev);
return result;
}
bool isvowel(char in)
{bool value=false;
switch(in)
{ case 'a':
case 'A':
case 'e':
case 'E':
case 'i':
case 'I':
case 'o':
case 'O':
case 'u':
case 'U': value= true;
}
return value;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.