Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 numbers{ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 };

array roots{ 1.0, 1.41, 1.73, 2.0, 2.24, 2.45 };

string letters = "abracadabra";

deque chars(letters.begin(), letters.end());

list flags{ true, true, true, true, true };

list> lists{ {0,1}, {2,3,5}, {8,13,21,34,55} };

set words{ "hello", "hi", "ta-ta", "bye" };

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{2, 3, 5}, lists )); // list of lists!

test( member( list{2, 3, 4}, lists ));

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Solaris 11.2 System Administration (oracle Press)

Authors: Harry Foxwell

1st Edition

007184421X, 9780071844215

More Books

Students also viewed these Databases questions