Write a program that simulates a coin-tossing game. At the beginning of the game, each of N players has a single fair coin and M points. The game performs a sequence of passes until only a minimum number of players remain. In a pass the players toss their coins into the air and when the coins fall to earth, the players count the number of coins that show heads and the number of coins that show tails. If the number of heads exceed the number of tails, then the players who tossed heads increase their points by an integer P and the players who tossed tails decrease their points by the same integer P. The players perform the opposite actions when the number of tails is greater than the number of heads. If the number of heads equals the number of tails, then no player’s points change. If any player’s points fall below one, then the player leaves the game, never to return.   The game employs a second integer K to compute P’s value. K’s and P’s initial values are one. After each pass, the game adds K to P and then adds one to K. After the first pass P’s value is two and K’s value is two. After the second pass, P’s value is four and K’s value is three. After the third pass, P’s value is seven and K’s value is four. After the fourth pass, P’s value is eleven and K’s value is five. In general,   P(k) = 1 + k(k - 1) / 2   What is the minimum number of players? It is your responsibility to determine the minimum number of players.

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter6: Modularity Using Functions
Section6.4: A Case Study: Rectangular To Polar Coordinate Conversion
Problem 9E: (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by...
icon
Related questions
Question

Please code in C++.

Write a program that simulates a coin-tossing game. At the beginning of the game, each of N players has a single fair coin and M points. The game performs a sequence of passes until only a minimum number of players remain. In a pass the players toss their coins into the air and when the coins fall to earth, the players count the number of coins that show heads and the number of coins that show tails. If the number of heads exceed the number of tails, then the players who tossed heads increase their points by an integer P and the players who tossed tails decrease their points by the same integer P. The players perform the opposite actions when the number of tails is greater than the number of heads. If the number of heads equals the number of tails, then no player’s points change. If any player’s points fall below one, then the player leaves the game, never to return.

 

The game employs a second integer K to compute P’s value. K’s and P’s initial values are one. After each pass, the game adds K to P and then adds one to K. After the first pass P’s value is two and K’s value is two. After the second pass, P’s value is four and K’s value is three. After the third pass, P’s value is seven and K’s value is four. After the fourth pass, P’s value is eleven and K’s value is five. In general,

 

P(k) = 1 + k(k - 1) / 2

 

What is the minimum number of players? It is your responsibility to determine the minimum number of players.

Before the game begins the program should display the players’ names, their points, and P and K. After each pass, the program should display the number of heads tossed, the number of tails tossed, the number of players tossing coins, and P and K. In addition to this information, for each player tossing a coin, the program should display the player’s name, coin toss outcome – heads or tails, and the player’s points. If a player’s points are less than zero, the program should display zero. Do not display information about players who have left the game. After the game ends the program should display the names of the players with the maximum number of points, and P and K. To be clear, there is only one maximum number of points.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr