In: Computer Science
Implement a method that does the following:
(a) Create a Map data structure to hold the associations between
player name (key) and team affiliation (value)
(b) Add at least 5 mappings to the map
(c) Print out the current roster of mappings
(d) Assuming some time has passed, change some of the mappings to simulate the players changing their affiliations
(e) Again, print out the current roster of mappings
3. Implement a main method that calls the above methods,
demonstrating their use with all applicable printed
output
code:
#include<bits/stdc++.h>
using namespace std;
void display(map<string,int> &m) //it displays
the map elements
{
map<string, int>::iterator itr;
for (itr = m.begin(); itr != m.end(); ++itr) {
cout << '\t' << itr->first<< '\t' <<
itr->second << '\n';
}
}
void add(map<string,int> &m,string s,int n)
//it adds elements in map
{
m[s]=n;
}
void update(map<string,int> &m,string s,int n)
//it updates the elements in map
{
m[s]=n;
}
int main()
{
map<string,int> m;
add(m,"john",1);
add(m,"varun",2);
add(m,"raman",3);
add(m,"joseph",4);
add(m,"vijay",5);
cout<<"Before update"<<endl;
display(m);
update(m,"john",2);
update(m,"varun",1);
cout<<"after
update"<<endl<<endl;
display(m);
}
output