Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4003CEM-testing/lab_vowels.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
24 lines (23 sloc)
945 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
#include <algorithm> | |
/** count_vowels() | |
* - takes a single parameter, a string | |
* - returns an integer value representing the number of vowel | |
* characters that were present in the input string. | |
* - y is not counted as a vowel | |
* - both upper and lowercase vowels are counted **/ | |
int count_vowels( const std::string &s ) | |
{ | |
/** I am using a number of C++ features in this function that | |
* have not been taught to you yet. But does this matter to you | |
* writing the testing code? | |
* It depends, if we are doing black-box testing then it doesn't, | |
* you don't care about how the function works just that it | |
* produces the right output/s for a given input/s. **/ | |
const std::string vowels = "aeiou"; | |
auto condition = [&vowels](char c) | |
{ | |
return std::find( begin(vowels), end(vowels), tolower(c) ) != end(vowels); | |
}; | |
return std::count_if( begin(s), end(s), condition ); | |
} |