Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ language 5) Writing more functions Task 5 simulates the answer to the greatest dodgeball player of all time while using functions. In the land

image text in transcribed C++ language

5) Writing more functions Task 5 simulates the answer to the greatest dodgeball player of all time while using functions. In the land of dodgeball mania, Player A, Player B, and Player Chad an argument over which one of them was the greatest dodgeball player of all time. To and the argument once and for all, they agreed on a dodgeball duel. Player Aisa poor shooter and only hits his target with a probability of 1/3. Player Bis a bit better and hits their target with a probability of 1/2. Player C is an expert shooter and never misses. A hit means a part of another player was hit with the ball and that person hit drops out of the duel. To compensate for the inequities in their marksmanship skills, it is decided that the contestants would fire in tums starting with Player A, followed by Player B, and then by Player C. The cycle would repeat until there was one man standing. And that player would be remembered as the greatest dodgeball player of all time. a. Write a function to simulate a single shot. It should use the following declaration: void shoot (bool GtargetAlive, double secuRCY) This would simulate someone shooting at targetAlive with the given accuracy by generating a random number between 0 and 1. If the random number is less than accuracy, then the target is hit and targetAlive should be set to false. You need to generate random numbers. For example, if Player B is shooting at Player C, this would be invoked as: shoot (PlayerClive, 1.0); Here, PlayerCalive is a Boolean variable that indicates if player is alive. These constants are setup already: 1/ Constanta const float PLAYERA ACCURACY - 100/3: comat float PLAYER_ACCURACY - 50; comet flot PLAYER_ACCURACY - 100 const int WOREDELS - 1000: b. An obvious strategy is for each player to shoot at the most accurate shooter still alive on the grounds that this shooter is the deadliest and has the best chance of hitting back. Write a second function named startDuel that uses the shoot function to simulate an entire duel using this strategy (or code for the second strategy below). It should loop until only one contestant is left, involving the shoot function with the proper target and probability of hitting the target according to who is shooting. The function should return a variable that indicates who won the duel. The prototype for startDuel is simple: int tartal); c. In your main function, invoke the startDuel function 1,000 times in a loop, keeping track of how many times each contestant wins. A counterintuitive strategy is for Player A to intentionally miss on his first shot. Thereafter, everyone uses the strategy of shooting at the most accurate shooter left in the game. This strategy means that Player A is guaranteed to live past the first round, since Player B and Player will fire at each other. Code the program to accommodate either one or the other, exclusive) strategy and output the probability of winning for each contestant. The code to output the probability for strategy two, for example, from inside of main could possibly look like this (excluding variable naming): ding the stage at the best so slive, del * has riyar A Laalaally at 1 La Alai " C Hall delayas Avec layer M/CEE) e del sc layer na die diyere layer Ck/CELEI

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

Spomenik Monument Database

Authors: Donald Niebyl, FUEL, Damon Murray, Stephen Sorrell

1st Edition

0995745536, 978-0995745537

More Books

Students also viewed these Databases questions