please use c++ here is the question: \"I\'ve been trying to track all the unique
ID: 3846372 • Letter: P
Question
please use c++
here is the question: "I've been trying to track all the unique Pokemon I've seen in my travels (I'm thinking of calling it a Pokedex). And, I've been wanting to try out the accumulate function from the numeric library.I've put all the names of the Pokemon I've seen (in order) in a vector (of string's), but I need a custom function (named 'unique_pokemon') that will only accumulate the pokemon the first time I've seen them. Please write that function so I can use it in my tests."
1 t includeExplanation / Answer
Here is the code you want to use . Please dont forget to rate the answer if it helped. Thank you very much
vector<string> unique_pokemon(const vector<string> &old_pokedex , const string & found_pokemon)
{
vector<string> new_pokedex(old_pokedex); //create a new vector from the old one
for(vector<string>::iterator it = new_pokedex.begin(); it != new_pokedex.end() ! ++it)
{
if(*it == found_pokemon) //if the new vector already has the found pokemon, dont add just return
return new_pokedex;
}
new_pokedex.push_back(found_pokemon); //did not find , so add the found pokemon and then return
return new_pokedex;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.