/*-------------------------------------------------- created by st10 at Tue Oct 25 14:10:13 PDT 2016 --------------------------------------------------*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> #include "is_empty.h" #include "first.h" #include "rest.h" #include "is_vowel.h" using namespace std; /*-------------------------------------------------- signature: count_vowels : string -> int purpose: expects a string, and returns how many vowels are in that string, where vowels are considered to be: aeiouAEIOU Q examples: count_vowels("") == 0 count_vowels("AUEIOaeiou") == 10 count_vowels("moo hey!") == 3 count_vowels("mmmmmmmmm") == 0 --------------------------------------------------*/ int count_vowels(string a_string) { if (is_empty(a_string)) { return 0; } else { if (is_vowel( first(a_string) )) { return 1 + count_vowels ( rest(a_string) ); } else { return 0 + count_vowels ( rest(a_string) ); } } }