Question: I am writing code, C + + , for a vacation based variant of the josephus problem. I need a file called testListMyJosephus.cpp . The

I am writing code, C++, for a vacation based variant of the josephus problem. I need a file called testListMyJosephus.cpp. The functions that test each implementation of the Josephus problem, may be called from a main()function, in a main.cpp file. These functions should implement the following steps:
1. Instantiate an object of the corresponding MyJosephus class with values for Nand M;
constraints: N >0and N <1025, M >=0and M < N;
2. Randomly select an integer value 125to determine which line, read from destinations.csv, is used to populate your different containers. (Note: The file uses ; as the separator instead of ,)
3. Read the line, parse it, and populate your container objects.
4. Run a full simulation until a trip destination is found.
5. After each elimination round, output the list of destinations by name and position/ID still left in the game, starting with the lowest ID; --{2. Seattle, WA,7. Boise, ID, etc.}
6. At the end of the simulation, report the elimination sequence and the chosen destination to the
screen.
the file below is what you should use to base this off of:
listMyJosephus.cpp
#include "listMyJosephus.h"
ListMyJosephus::ListMyJosephus(int M, int N) : M(M), N(N){}
ListMyJosephus::~ListMyJosephus(){}
void ListMyJosephus::clear(){
destinations.clear();
}
int ListMyJosephus::currentSize(){
return destinations.size();
}
bool ListMyJosephus::isEmpty(){
return destinations.empty();
}
std::string ListMyJosephus::eliminateDestination(){
if (isEmpty())
return "";
auto it = destinations.begin();
for (int i =0; i < M -1; ++i){
++it;
if (it == destinations.end())
it = destinations.begin();
}
std::string eliminatedDestination =*it;
it = destinations.erase(it);
if (it == destinations.end())
it = destinations.begin();
return eliminatedDestination;
}
void ListMyJosephus::printAllDestinations(){
for (const auto& dest : destinations){
std::cout << dest <<"";
}
std::cout << std::endl;
}

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 Databases Questions!