Create a class of function objects called StartsWith that satisfies the following specification: when initialized with character c, an object of this class behaves as a unary predicate that determines if its string argument starts with c. For example, StartsWith(’a’) is a function object that can be used as a unary predicate to determine if a string starts with an a. So StartsWith(’a’)("alice") would return true but StartsWith(’a’)("bob") would return false. The function objects should return false when called on an empty string. Test your function objects by using one of them together with the STL algorithm count_if to count the number of strings that start with some letter in some vector of strings
Can you write a C++ program for this:
Create a class of function objects called StartsWith that satisfies the following specification: when initialized with character c, an object of this class behaves as a unary predicate that determines if its string
argument starts with c. For example, StartsWith(’a’) is a function
object that can be used as a unary predicate to determine if a string starts
with an a. So StartsWith(’a’)("alice") would return true but
StartsWith(’a’)("bob") would return false. The function objects
should return false when called on an empty string. Test your function
objects by using one of them together with the STL
to count the number of strings that start with some letter in some vector
of strings
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 3 images