In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.
Chapter 21 // Drill 2.1
Define a map<string, int> called msi.
Chapter 21 // Drill 2.2
Insert ten (name, value) pairs into it, e.g., msi["lecture"]=21.
Chapter 21 // Drill 2.3
Output the (name, value) pairs to cout in some format of your choice.
Chapter 21 // Drill 2.4
Erase the (name, value) pairs from msi.
Chapter 21 // Drill 2.5
Write a function that reads value pairs from cin and places them in msi.
Chapter 21 // Drill 2.6
Read 10 pairs from input and enter them into msi.
Chapter 21 // Drill 2.7
Write the elements of msi to cout.
Chapter 21 // Drill 2.8
Output the sum of the (integer) values in msi.
Chapter 21 // Drill 2.9
Define a map<int, string> called mis.
Chapter 21 // Drill 2.10
Enter the values from msi into mis; that is, if msi has an element ("lecture",21), mis should have an element (21, "lecture").
Chapter 21 // Drill 2.11
Output the elements of mis to cout.
Github: https://github.com/l-paz91/principles-practice/blob/master/Chapter%2021/Drill%202%20-%20All%20drills
For Drill 2.4 I wasn't sure if he meant erase a few or erase all so I went with erase all.
With Drill 2.7 I think he meant create an overload of the output operator for the map as creating a print function has already been done.
Whilst doing 2.9 I decided to make my functions more generic so they could accept maps of almost any type.
No comments:
Post a Comment