Answered step by step
Verified Expert Solution
Link Copied!

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 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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

How are is it for new competitors to enter your market

Answered: 1 week ago