#include #include #include #include using namespace std; const string vowels = "aeiouy"; // y is not always counted as a vowel but included here anyway class Consonant { public: // a letter is a consonant if it cannot be found among the vowels bool operator() (char c) { return (find(vowels.begin(), vowels.end(), c) == vowels.end()); } }; void main() { string s; cout << "Please enter a string: " << endl; cin >> s; cout << "Number of consonants in string: " << count_if(s.begin(), s.end(), Consonant()) // use function object as predicate << endl; cout << "Number of upper case letters in string: " << count_if(s.begin(), s.end(), isupper) // use standard function isupper as predicate << endl; }