Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 mainfunction in a main.cpp file. These functions should implement the following steps:
Instantiate an object of the corresponding MyJosephus class with values for Nand M;
constraints: N and N M and M N;
Randomly select an integer value to determine which line, read from destinations.csv is used to populate your different containers. Note: The file uses ; as the separator instead of
Read the line, parse it and populate your container objects.
Run a full simulation until a trip destination is found.
After each elimination round, output the list of destinations by name and positionID still left in the game, starting with the lowest ID; Seattle, WA Boise, ID etc.
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::ListMyJosephusint M int N : MM NN
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 ; i M ; i
it;
if it destinations.end
it destinations.begin;
std::string eliminatedDestination it;
it destinations.eraseit;
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started