Question
C++ / Visual Studio Implement the member function below that returns true if the given value is in the container, and false if not. Your
C++ / Visual Studio
Implement the member function below that returns true if the given value is in the container, and false if not. Your code should use iterators so it works with any type of container and data.
template< typename Value, class Container >
bool member( const Value& val, const Container& cont );
just implement this function in the code below
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define test(result) { cout << (result ? "yes" : "no") << endl; }
template< typename Value, class Container >
bool member( const Value& val, const Container& cont )
{
// your code goes here
}
int main() {
vector
array
string letters = "abracadabra";
deque
list
list> lists{ {0,1}, {2,3,5}, {8,13,21,34,55} };
set
test( member( 21, numbers )); // vector of integers
test (member( 42, numbers ));
test( member( 2.0, roots )); // array of decimal roots
test( member( 3.14, roots ));
test( member( 'c', letters )); // string object
test( member( 'k', letters ));
test( member( 'd', chars )); // deque of characters
test( member( 't', chars ));
test( member( true, flags )); // list of booleans
test( member( false, flags ));
test( member( list
test( member( list
test( member( "hi", words )); // set of strings
test( member( "no", words ));
system("pause");
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started