Answer to Question #183018 in C++ for Vincenzo Santoro

Question #183018

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.


1
Expert's answer
2021-04-29T13:57:58-0400
#include <iostream>
#include <string>
using namespace std;
string vowels = "aeiou";
bool is_vowel(char c){
    for(int i = 0; i < vowels.length(); i++){
        if(c == vowels[i]) return true;
    }
    return false;
}
string remove_vowels(string str){
    string temp = "";
    for(int i = 0; i < str.length(); i++){
        if(!is_vowel(str[i])) temp += str.substr(i,1);
    }
    str = temp;
    return str;
}
int main(){
    string str = "There";
    cout<<"Input string: ";
    cin>>str;
    cout<<remove_vowels(str);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS