The class is voting for a class pet, and votes holds how many votes each pet got. Write top_pet(votes) to return the pet with the most votes. On a tie, pick the one that comes first alphabetically; if nobody voted (empty), return "".
top_pet({{"cat", 12}, {"dog", 15}, {"fish", 3}})→'dog'top_pet({})→''string top_pet(const map<string, int> &votes)#include <map>
#include <string>
using namespace std;
string top_pet(const map<string, int> &votes) {
string best = "";
int most = -1;
for (const auto &p : votes) {
// your code here: if it has more than most, remember it
}
return best;
}
Run tries the examples. When they look right, Submit.