Question
In this assignment, you will implement a method to solve the Josephus problem. The Josephus problem is a theoretical problem related to a certain counting-out
In this assignment, you will implement a method to solve the Josephus problem.
The Josephus problem is a theoretical problem related to a certain counting-out game. It involves some number of people standing around in a circle waiting to be executed. The count begins somewhere in the circle and goes around the circle in one direction. A number of people are skipped, and then the next person is executed. The cycle repeats starting with the next person still alive and continues until only one is left, the survivor. You can read more about it in the provided link at the top of this page.
This program should implement a class to facilitate a solution to the Josephus problem. The purpose of having you do this is to ensure that you can correctly do the following:
Use namespaces
Use exceptions
Use the STL
Think about how a larger problem and the smaller pieces of it relate
This program should:
Implement a solution to the Josephus problem using a templated class from the STL of your choice.
Throw appropriate exceptions for anything that might cause an error or be inefficient in some way. You can use built in exceptions, but you should also create a custom exception class for various risks specific to the Josephus problem. Examples of this could include:
0 or negative values for the number of people or other arguments
Initial number of people a ridiculously large size
Trying to get the next person to kill when there is only one person left
Because we use 0 indexing, and the Wikipedia problem assumes a 1 indexed standard, theres a great possibility for off-by-one errors, so be especially cognizant of this.
Ask for a number of people to start with (with a default skip value of 1 person so that every second person is executed).
Ask for input for the number (index) of the person to start with, then finally output the number (index) of the person that would ultimately survive.
Include a namespace somewhere in the program in a reasonable place.
Have a main function that thoroughly tests your implementation of the solution. It should test all the operations declared in the class and output what it is doing along the way to both help with debugging and prove your code works.
Have at least 4 files -> a header file for the templated class, a main.cpp for testing purposes, a README.txt, and a makefile. More files are encouraged to modularize your code.
All methods must be tested.
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