Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C# problem : Create a Map class that stores a collection of key/value pairs. The

ID: 3698679 • Letter: C

Question

C# problem :

Create a Map class that stores a collection of key/value pairs. The key/value pairs should be implemented using a Pair class that has the fields and properties First and Second. The Pair class and the Map class must be generic so that the keys can be of any type and the values can be of any type. The Map class should include methods for adding a new key/value pair, searching for a value by supplying the key, returning all the keys in a map, clearing the map in order to start over, and a size method that returns the number of key/value pairs in the map

Use the Map class in an application of your choosing. You can implement a word dictionary or a phone book or something else that functions like a dictionary

Explanation / Answer

[SerializableAttribute] [DefaultMemberAttribute("Item")] public class Map : CompoundValue, IDictionary, ICollection, IEnumerable, IEnumerable config ParameterCombination: Main { action abstract static bool Implementation.AddKey(string key) where key in { "green", "yellow", "red" }; action abstract static bool Implementation.RemoveKey(string key) where key in { "green", "yellow", "cyan" }; action abstract static void Implementation.SetValues(Map valuesMap) where valuesMap in { Map{ "green"->1, "blue"->3, "cyan"->5 }, Map{ "green"->5, "red"->4, "yellow"->7 }, Map{} }; action abstract static Map Implementation.GetValues(Set keySet) where keySet in { Set{ "green", "blue" }, Set{ "red", "orange" }, Set{ "cyan" }, Set{} }; action abstract static Sequence Implementation.RemoveDuplicateElements(Sequence queue) where queue in { Sequence{ 1, 3, 2 }, Sequence{ 2, 2, 2 }, Sequence{ 1 }, Sequence{} }; } namespace CollectionInitializers { static class PropertiesModel { private static MapContainer properties = new MapContainer(); [Rule] static bool AddKey(string key) { if (properties.ContainsKey(key) || key == null) { return false; } else { properties[key] = 0; return true; } } [Rule] static bool RemoveKey(string key) { return properties.Remove(key); } [Rule] static Set GetKeys() { return new Set(properties.Keys); } [Rule] static void SetValues(Map valuesMap) { if (valuesMap == null) return; foreach (string key in valuesMap.Keys) { if (properties.ContainsKey(key)) { properties[key] = valuesMap[key]; } } } [Rule] static Map GetValues(Set keySet) { if (keySet == null) return new Map(); MapContainer tempMap = new MapContainer(); foreach (string key in keySet) { if (properties.ContainsKey(key)) { tempMap.Add(key, properties[key]); } } return new Map(tempMap); } [Rule] static void Clear() { properties.Clear(); } [Rule] static Sequence RemoveDuplicateElements(Sequence queue) { return (queue != null) ? new Sequence(queue.Distinct()) : new Sequence(); } } }