Estoy empesando en c++ con un libro que me compre y no entiendo estos dos ejercicios por favor que alguien me pueda ayudar gracias. Gracias anticipadas.
1) In the land of Puzzlevania, Aaron, Bob, and Charlie had an argument over which one of them was the greatest puzzler of all time. To end the argument once and for all, they agreed on a duel to the death. Aron is a poor shooter and only hits his target with a probability of 1/3. Bob is a bit better and hits his target with a probability of ½. Charlie is an expert marksman and never misses. A hit means a kill and the person hit drops out of the duel.
A) Write a function to simulate a single shot. It should use the fallowing declaration:
Void shoot(bool& targetAlive, double accuracy);
This would simulate someone shootine at targetAlive with the given accuracy by generating a random number between 0 and 1. If the random number is less tha accuracy, then the target is hit and targetAlive should be set to false. Appendix 4 illustrates how to generate random numbers.
For example, if Bob is shooting at Charlie, this could be invoked as: shoot(charlieAlive, 0.5);
B) An obvious strategy is for each man 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. It should loop until only one contestant is left, invoking 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.
C) In your main function, invoke the startDuel function 1,000 times in a loop, keeping track of how many times each contestant wins. Output the probability that each contestant will win when everyone uses the strategy of shooting at the most accurate shooter left alive.
D) A counterintuitive strategy is for Aaron to intentionally miss on his first shot. Thereafter, everyone uses the strategy of shooting at the accurate shooter left alive. This strategy means that Aaron is guaranteed to live past the first round , since Bob and Charlie will fire at each other. Modify the program to accommodate this new strategy and output the probability of winning for each contestant.
5) Write a program that will correct a C++ program that has errors in which operator, <<or>>, it uses with cin and cout. The program replaces each (incorrect) occurrence of
with the corrected version
and each (incorrect) occurrence of
with the corrected version
For an easier version, assume that these is always exactly one blanck space between any occurrence of cin and a following << and similarly assume that there is always exactly one blanck space between each occurrence of cout and a following>>
For a harder version, allow for the possibility that there may be any number of blanks, even zero blanks between cin and << and between cout and >>. In this harder case the replacement corrected version has only one blank between the cin or cout and the following operator. The program to be corrected is in one file and the corrected version is output to a second file. Your programs should define a function that is called with the input- and output0 file streams as arguments.