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.
#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;
}
Comments
Leave a comment