logo CodeStepByStep logo


Language/Type: C++ Map collections
Related Links:
Author: Marty Stepp (on 2016/06/16)

Write a function named intersection that accepts as parameters two references to Maps of strings to integers, and that returns a new map whose contents are the intersection of the two. The intersection of two maps is defined here as the set of key/value pairs that exist in both maps. So if some key K maps to value V in both the first and second map, include it in your result. If K does not exist as a key in both maps, or if K does not map to the same value V in both maps, exclude that pair from your result. For example, consider the following two maps:

{"Alyssa":100, "Janet":87, "Jeff":88, "Kim":52, "Logan":62, "Stefanie":80, "Sylvia":95, "Whitaker":46}
{"Brian":60, "Jeff":88, "Kim":52, "Lisa":83, "Logan":62, "Stefanie":80, "Sylvia":87, "Whitaker":52}

Calling your function on the preceding maps would return the following new map:

{"Jeff":88, "Kim":52, "Logan":62, "Stefanie":80}
Type your C++ solution code here:

This is a function problem. Write a C++ function as described. Do not write a complete program; just the function(s) above.

You must log in before you can solve this problem.

Log In

Need help?

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.

© Marty Stepp, all rights reserved.