Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

PostgreSQL Up And Running A Practical Guide To The Advanced Open Source Database

Authors: Regina Obe, Leo Hsu

3rd Edition

1491963417, 978-1491963418

Students also viewed these Databases questions

Question

How do members envision the ideal team?

Answered: 1 week ago

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago