Question

In: Computer Science

Implement a method that does the following: (a) Create a Map data structure to hold the...

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

Solutions

Expert Solution

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


Related Solutions

0. Introduction. This laboratory assignment involves implementing a data structure called a map. A map associates...
0. Introduction. This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called...
This laboratory assignment involves implementing a data structure called a map. A map associates objects called keys with other objects called values. It is implemented as a Java class that uses arrays internally. 1. Theory. A map is a set of key-value pairs. Each key is said to be associated with its corresponding value, so there is at most one pair in the set with a given key. You can perform the following operations on maps. You can test if...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you...
Java: Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items in the...
Program in Java Create a class and name it MyArray and implement following method. * NOTE:...
Program in Java Create a class and name it MyArray and implement following method. * NOTE: if you need more methods, including insert(), display(), etc. you can also implement those. Method name: getKthMin(int k) This method receives an integer k and returns k-th minimum value stored in the array. * NOTE: Items in the array are not sorted. If you need to sort them, you can implement any desired sorting algorithm (Do not use Java's default sorting methods). Example: Items...
Create a class BankAccount to hold at least the following data / information about a bank...
Create a class BankAccount to hold at least the following data / information about a bank account: Account balance Total number of deposits Total number of withdrawals Interest rate e.g., annual rate = 0.05 Service charges per month The class should have the following member functions: Constructor To set the required data. It may be parameterized or user’s input. depositAmount A virtual function used to accept an argument for the amount to be deposited. It should add the argument (amount)...
CS 209 Data Structure 2. Create a method that takes a HashMap and returns the sum...
CS 209 Data Structure 2. Create a method that takes a HashMap and returns the sum of the keys of the HashMap. 3. Create a method that takes a HashMap and returns the sum of all keys and values of the HashMap. For example, if the input is [1=9, 3=6, 4=9, 6=8, 7=6] then the method should return 59.
CS 209 Data Structure 1. Create a method that takes an ArrayList of Integer and returns...
CS 209 Data Structure 1. Create a method that takes an ArrayList of Integer and returns a sorted copy of that ArrayList with no duplicates. Sample Input: {5, 7, 4, 6, 5, 6, 9, 7} Sample Output: {4, 5, 6, 7, 9}
PLEASE Create a perceptual map using the following data: After researching the demographic and competitive profile...
PLEASE Create a perceptual map using the following data: After researching the demographic and competitive profile of several markets, they decided Dallas, Texas, would be the best place to start their business. In examining the markets, they were looking for a town that would best fit their target market of singles and families in the age range of 18 to 50. The population of Dallas was almost 5.5 million people, of which about 50 percent were between the ages of...
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String...
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String and returns a copy of that ArrayList with no duplicates. The relative ordering of elements in the new ArrayList should be the same. Sample Input: {"qwerty", "asdfgh", "qwer", "123", "qwerty", "123", "zxcvbn", "asdfgh"} Sample Output: {"qwerty", "asdfgh", "qwer", "123", "zxcvbn"}
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT