Answered step by step
Verified Expert Solution
Link Copied!

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().
1.(5 pts) After each elimination round, output the list of (4 pts) Instantiate an object of the corresponding MyJosephus class with values for Nand M;
constraints: N >0and N <1025, M >=0and M < N;
2.(2 pts) 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 , We did
so as the city string contains a comma example: Boise, ID)
3.(10 pts) Read the line, parse it, and populate your container objects.
4.(5 pts) Run a full simulation until a trip destination is found.destinations by name and position/ID still left in the game, starting from the lowest destination ID; --{2. Seattle, WA,7. Boise, ID, etc.}
6.(2 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.
7.(7 pts) Output the following timing statistics to a file called results.log.
\deg Initial values for N and M in the format N=value1, M=value2,
\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 5(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.
8. The timing statistics should be in seconds or milliseconds or microseconds
a)destination.cpp
#include "destination.h"
#include
Destination::Destination(int position, std::string name) : position(position), name(name){}
Destination::~Destination(){}
void Destination::printPosition() const {
std::cout << "Position: "<< position << std::endl;
}
void Destination::printDestinationName() const {
std::cout << "Destination Name: "<< name << std::endl;
}
b)vectorMyJosephus.cpp
#include "vectorMyJosephus.h"
VectorMyJosephus::VectorMyJosephus(int M, int N) : M(M), N(N){}
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 =0;
idx =(idx + M -1)% destinations.size();
std::string eliminatedDestination = destinations[idx];
destinations.erase(destinations.begin()+ 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

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

Making Databases Work The Pragmatic Wisdom Of Michael Stonebraker

Authors: Michael L. Brodie

1st Edition

1947487167, 978-1947487161

More Books

Students also viewed these Databases questions

Question

What is the best conclusion for Xbar Chart? UCL A X B C B A LCL

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago