Question: Part C - 2 : RemoveHero Add a method called RemoveHero to the HeroesDB class. Declare your method in the HeroesDB.h file and define the

Part C-2: RemoveHero
Add a method called RemoveHero to the HeroesDB class. Declare your method in the HeroesDB.h file and define the method in the HeroesDB.cpp file (C++Class Methods
(w3schools.com)).The method should take a string parameter that is the name of the hero to remove.
In the method, if _groupedHeroes is empty, call the GroupHeroes method.
Check if the _groupedHeroes map contains a key with the first letter of the name.
If the key is not found, print a message saying the hero was not found.
If the key is found, then get the vector for the key. The vector is the value stored in the map for the key.
call the BinarySearch method to get the index of the hero to remove for the vector.
If BinarySearch returns the index
then remove the hero from the vector
search for the hero in the _heroes vector and remove the hero from the _heroes vector.
Print that the hero was removed.
NOTE: if removing the hero makes the vector empty for the letter, then remove the letter (which is the key)from the map.
If BinarySearch returns -1(meaning the hero is not in the vector),print a message that the hero was not found.
In main (which is in HeroesV2.cpp),add code to case 6of the switch. Using Input::GetString, ask the user to enter the name to find. Call RemoveHero passing the string that the user enters.
make sure that if the method is called again that the same hero searched for in the first call is no longer in the map.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!