Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I can\'t get my code to do what it is supposed to. Below is adescription of what

ID: 3610398 • Letter: I

Question

I can't get my code to do what it is supposed to. Below is adescription of what the code is supposed to do and the code that Icame up with:

Here is what the code is supposed to do:

The member function whosLeft takes as input a vector of stringsnames and an integer k, and it returns the string that correspondsto the last element of names that is removed by the followingprocess. To begin, we start at the first element of the vector, andwe start counting. When we reach the kth element, we remove it.Starting at the next element, we again start counting. When we gopast the end of the vector, we start over again at the firstelement. When we reach the kth element again, we remove it. Thisprocess continues until there is exactly one element left in thearray.
For example, if k is equal to 3 and the vector names contains thestrings Joe, Bob, Kathy, Larry, and Sandy, then the first elementremoved is Kathy. The next element removed is Joe. After that,Sandy is removed. Finally, Bob is removed. So, the last onestanding is Larry.

Here is my code:

string whosLeft(vector<string> names, int k) {
    string name;

    while(k == 1 || k < names.size()) {
      name = names.at(k);
      names.erase(names.begin() + 1,names.begin() + k);
    }
    return name;
}

Explanation / Answer

     str_Vector.erase(str_Vector.begin()+1,str_Vector.begin()+2);

  I hope it is useful toyou.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote