Roman Roulette:
Write this program in C++
Background
The historian H relates how, in the conflict of 67 C.E., the Romans took the town of Jotapata which he was commanding. Escaping, He found himself trapped in a cave with 40 companions. The Romans discovered his whereabouts and invited him to surrender, but his companions refused to allow him to do so. He, therefore, suggested that they kill each other, one by one, the order to be decided by lot. Tradition has it that the means for effecting the lot was to stand in a circle, and, beginning at some point, count round, every third person being killed in turn. The sole survivor of this process was H, who then surrendered to the Romans. Which begs the question: had H previously practiced quietly with 41 stones in a dark corner, or had he calculated mathematically that he should adopt the 31st position in order to survive?
Having read an account of this gruesome event you become obsessed with the fear that you will find yourself in a similar situation at some time in the future. In order to prepare yourself for such an eventuality, you decide to write a program to run on your mobile phone which will determine the position in which you should stand to ensure that you will be the sole survivor.
In particular, your program should be able to handle the following processes. n > 0 people are initially arranged in a circle, facing inwards, and numbered from 1 to n clockwise. The numbering from 1 to n proceeds consecutively in a clockwise direction. Starting with person number 1, counting starts in a clockwise direction, until we get to person number k (k > 0), who is promptly killed. We then proceed to count a further k people in a clockwise direction, starting with the person immediately to the left of the victim (that is, the victim’s left). That kth person is killed next, and so on until only one person remains.
For example, when n = 5, and k = 1, the players are eliminated in order, and player 5 wins. If n = 5 and k = 2, the order of elimination is 2, 4, 1, 5, and player 3 wins. Note that players are not renumbered after each death: everyone keeps their initial number until the end (or their end).
Statement of Work
Write a program to solve the H problem for general values of n > 0 and k ≥ 0. Your program must read the values of n and k from cin and write the winners for to cout. Each problem will be on its own input line containing values for n and k (in that order). For each input problem, your program should output a single line containing only the number of the survivor (so you’ll know in which position to stand). Your program may assume that both n and k can be held by int variables
End Expected Output
killed 3
killed 6
killed 9
killed 12
.
.
.
the survivor is 31.
Please find the code for H Problem below:
#include <iostream>
using namespace std;
int main()
{
int n, k;
cout<<"Enter the value of n:";
cin>>n; // Ex: n = 5
cout<<"Enter the value of k:";
cin>>k; // Ex: k = 2
int killed[n]; // Array to keep track of people, both killed and
alive
/*
* Initializing the array with 0's. 0- Alive, 1- Killed
* killed = [0, 0, 0, 0, 0]
*/
for(int i=0;i<=n;i++) {
killed[i] = 0;
}
/*
* p is the position of the person to be killed
* Here, p=(2-1)=1 because array index starts from 0 (Ex: k=2)
*/
int p = k-1;
int numAlive = n; // numAlive = 10
/*
* Run the loop until there is only one person alive
* After 1st iteration, killed = [0, 1, 0, 0, 0]
* After 2nd iteration, killed = [0, 1, 0, 1, 0]
* After 3rd iteration, killed = [1, 1, 0, 1, 0]
* After 4th iteration, killed = [1, 1, 0, 1, 1]
*/
while(numAlive > 1) {
p = p % n;
killed[p] = 1; // Kill the person in kth position, put 1 in that
position in array "killed"
cout<<"Killed "<<p+1<<endl;
numAlive--; // Decrement the number of people alive
int count = 0;
/*
* Find the next kth person by skipping all the people dead
* i.e. Ignoring array entries containing 1
*/
while(count != k) {
if(killed[(++p) % n] == 0) {
count++;
}
}
}
/*
* Loop through the array and find the only person alive
* i.e. Find the array position containing 0.
* i+1 has to be printed as array index starts from 0.
*/
for(int i=0;i<n;i++) {
if(killed[i] == 0) {
cout<<"the survivor is "<<i+1;
break;
}
}
return 0;
}
Below are the screenshots:


Below are the outputs:


Hope this would suffice your requirement and also hoping for a positive review.
Roman Roulette: Write this program in C++ Background The historian H relates how, in the conflict...
Flavius Josephus was a famous historian of the first century, but apparently, he would not have lived to become famous without the exercise of his computational and mathematical abilities. A legend says that during the Jewish-Roman war he was part of a band of 41 rebels trapped in a cave by the Romans. To avoid capture, the rebels decided to form a circle and proceeded to kill every third remaining person until no one was left. However, Josephus quickly calculated...
C++ programming language, starting out with C++. Looping Constructs Write a program to simulate the casino game "craps". It should execute N number of games so that you can compute the probability(%) of the "player" winning and the "house" winning. Probability(%) of the "player" winning = PlayerWins / N * 100. Probability(%) of the "house" winning = HouseWins / N * 100. The rules are: Player rolls two dice. When the sum is 7 or 11 on first throw, player...
Need different C code then what has been posted here Problem In this assignment, you have to simulate the Josephus problem. There are n number of prisoners standing in a circle waiting to be executed. The counting out begins at some point in the circle and proceeds around the circle in a fixed direction. In each step, a certain number of people are skipped and the next person is executed. The elimination proceeds around the circle (which is becoming smaller...
write a C# program using replit that uses a loop to input # at bats and # of hits for each of the 9 baseball players on a team. Team name, player name, and player position will also be input.(two dimensional array) The program should then calculate and print the individual batting average and, after all 9 players have been entered, calculate and print the team batting average. Example of inputs and Outputs... Enter the Team name: (one time entry)...
Tic-Tac-Toe (arrays and multidimensional arrays) C++ Write an interactive program that plays tic-tac-toe. Represent the board as a 3 X 3 character array. Initialize the array to blanks and ask each player in turn to input a position. The first player's position is marked on the board with a O and the second player's position is marked with an X. Continue the process until a player wins or the game is a draw. To win, a player must have 3...
(c++ only)Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: When the program begins, the user enters his or her choice of “rock”, “paper”, or “scissors” at the keyboard using a menu in a function, userChoice, that returns a character. Next, there should be a function, computerChoice, that generates the computer’s play. A random number in the range of 1 through 3 is generated. If the...
Structures in C++ :- 1. Write a program that declares a structure to store the code number, salary and grade of an employee. The program defines two structure variables, inputs record of two employees and then displays the record of the employee with more salary. 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then...
Structures in C++ :- 2. Write a program that declares a structure to store the distance covered by player along with the time taken to cover the distance. The program should input the records of two players and then display the record of the winner. 3. Write a program that declares a structure to store income, tax rate and tax of a person. The program defines an array of structure to store the records of five person. It inputs income...
Write a Java program that displays the following menu to the user (and allows the user to make a valid selection): 1- Tournament Selection 2- Magic Squares 3 -Arrival Time 4- Quit Once a valid selection is made, your program will run the appropriate code for each program. The description for each program is as follows: In a tournament, each player plays six games and then they are 1 - Tournament Selection: placed in a specific group based on their...
C++ Implement Hot Potato game ________________________________________________ A group of people, numbered 1 to N, are sitting in a circle. Starting at person 1, a hot potato is passed. After X passes, the person holding the hot potato is eliminated, the circle closes ranks, and the game continues with the person who was sitting after the eliminated person picking up the hot potato. The last remaining person wins. For example: if X = 0 and N = 5, players are eliminated...