Answer to Question #255853 in C++ for becky

Question #255853

Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, and otherwise returns false. Also write a program to test your method.


1
Expert's answer
2021-10-24T05:53:26-0400
#include <iostream>
#include <string>
using namespace std;

bool isVowel(char ch) {
    const string vowels = "aeiouAEIOU";
    if (vowels.find(ch) == string::npos) {
        return false;
    }
    return true;
}

int main() {
    string s;

    cout << "Enter a string: ";
    getline(cin, s);


    int count=0;
    for (int i=0; i<s.size(); i++) {
        if (isVowel(s[i])) {
            count++;
        }
    }

    cout << "Threre are " << count << " vowels in your string" << endl;
}

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