Write a program that prompts the user to input a string. The program then uses t
ID: 3619409 • 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. Our program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. i only want a hint though... 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. Our program must contain a function to remove all the vowels and a function to determine whether a character is a vowel. i only want a hint though...Explanation / Answer
//There you have a little hint... #include <iostream> #include <string> using namespace std;bool is_a_vowel (char c){ if (c=='A' or c=='a' or c=='E' or c=='e' or c=='I' or c=='i' or c=='O' or c=='o' or c=='U' or c=='u') return true; else return false; }
string remove_vowels (string st){ for (int i=0;i<st.size();i++){ if (is_a_vowel(st[i])==true){ st=st.substr(0,i)+st.substr(i+1,st.size()-i); i--; } } return st; }
int main(){ string st; cin>>st; cout<<remove_vowels(st)<<endl; system ("pause"); } //There you have a little hint... #include <iostream> #include <string> using namespace std;
bool is_a_vowel (char c){ if (c=='A' or c=='a' or c=='E' or c=='e' or c=='I' or c=='i' or c=='O' or c=='o' or c=='U' or c=='u') return true; else return false; }
string remove_vowels (string st){ for (int i=0;i<st.size();i++){ if (is_a_vowel(st[i])==true){ st=st.substr(0,i)+st.substr(i+1,st.size()-i); i--; } } return st; }
int main(){ string st; cin>>st; cout<<remove_vowels(st)<<endl; system ("pause"); } //Enjoy it!
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.