Write a function object equalsk equalsk contains one data


Question: Although the function objects we have looked at store no data, this is not a requirement. Reuse the interface in Exercise (a).

a. Write a function object EqualsK. EqualsK contains one data member (k). EqualsK is constructed with a single parameter (the default is zero) that is used to initialize k. Its method returns true if the parameter is equal to k.

b. Use EqualsK to test countMatches in Exercise (c).

Exercise: This exercise asks you to write a generic countMatches method. Your method will take two parameters. The first parameter is an array of int. The second parameter is a function object that returns a Boolean.

a. Give a declaration for an interface that expresses the requisite function object.

b. countMatches returns the number of array items for which the function object returns true. Implement countMatches.

c. Test countMatches by writing a function object, EqualsZero, that implements your interface to accept one parameter and returns true if the parameter is equal to zero. Use an EqualsZero function object to test countMatches.

Solution Preview :

Prepared by a verified Expert
Basic Computer Science: Write a function object equalsk equalsk contains one data
Reference No:- TGS02457500

Now Priced at $15 (50% Discount)

Recommended (98%)

Rated (4.3/5)