Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C + + create a file TestVectorMyJosephus.cpp . The functions of the Josephus problem, may be called from main ( ) . 1 . (
C create a file TestVectorMyJosephus.cpp The functions of the Josephus problem, may be called from main
pts After each elimination round, output the list of pts Instantiate an object of the corresponding MyJosephus class with values for Nand M;
constraints: N and N M and M N;
pts 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 We did
so as the city string contains a comma example: Boise ID
pts Read the line, parse it and populate your container objects.
pts Run a full simulation until a trip destination is found.destinations by name and positionID still left in the game, starting from the lowest destination ID; Seattle, WA Boise, ID etc.
pts At the end of the simulation, report the elimination sequence and the chosen destination to the
screen. Below image illustrates a sample output for testing ListMyJosephus. A similar result should be
displayed for VectorMyJosephus.
pts Output the following timing statistics to a file called results.log
deg Initial values for N and M in the format Nvalue Mvalue
deg total time for running the simulation,
deg average elimination time which is the average for the time spent between two consecutive eliminations.
Important note: While recording both these times, do NOT include time for step which prints the pending list after each round You can comment out that part of the code while measuring
performance. It is there strictly for your debugging reasons.
The timing statistics should be in seconds or milliseconds or microseconds
adestinationcpp
#include "destination.h
#include
Destination::Destinationint position, std::string name : positionposition namename
Destination::~Destination
void Destination::printPosition const
std::cout "Position: position std::endl;
void Destination::printDestinationName const
std::cout "Destination Name: name std::endl;
bvectorMyJosephuscpp
#include "vectorMyJosephus.h
VectorMyJosephus::VectorMyJosephusint M int N : MM NN
VectorMyJosephus::~VectorMyJosephus
void VectorMyJosephus::clear
destinations.clear;
int VectorMyJosephus::currentSize
return destinations.size;
bool VectorMyJosephus::isEmpty
return destinations.empty;
std::string VectorMyJosephus::eliminateDestination
if isEmpty
return ;
int idx ;
idx idx M destinations.size;
std::string eliminatedDestination destinationsidx;
destinations.erasedestinationsbegin idx;
return eliminatedDestination;
void VectorMyJosephus::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