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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education