Line: 1 to 1  

 
Changed:  
< <  Due: Oct 3, 11:55pm  
> >  Due: Feb 22, 11:55pm  
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions 
Line: 1 to 1  

 
Changed:  
< <  Due: Feb 23, 11:55pm  
> >  Due: Oct 3, 11:55pm  
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions 
Line: 1 to 1  

 
Line: 30 to 30  
%CODE{"c++"}% void computeCoins(int coinValue, int& number, int& amountLeft); //Precondition: 0 < coinValue < 100; 0 <= amountLeft < 100.  
Changed:  
< <  //(CoinValue will always be 24, 10, or 1 for this project)  
> >  //(CoinValue will always be 25, 10, or 1 for this project)  
//Postcondition: number has been set equal to the maximum number of coins of //denomination coinValue cents that can be obtained from amountLeft //amountLeft has been decreased by the value of the coins to be returned, that is, 
Line: 1 to 1  

 
Changed:  
< <  Due: Oct 5, 11:55pm  
> >  Due: Feb 23, 11:55pm  
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions  
Line: 21 to 21  
Problem 1  Change Computation  
Changed:  
< <  This is a very simple program. It is merely a main function that calls the computeCoin function. The trick is that you MUST follow a "specification" (given below) to write the computeCoin function to work exactly as the the comments in the declaration below specify. The learning goals here are:  
> >  This is a very simple program. It is merely a main function that calls the computeCoin function. The trick is that you MUST follow a "specification" (given below) to write the computeCoin function to work exactly as the the comments in the declaration below specify. The learning goals here are:  

Line: 1 to 1  

 
Line: 21 to 21  
Problem 1  Change Computation  
Added:  
> >  This is a very simple program. It is merely a main function that calls the computeCoin function. The trick is that you MUST follow a "specification" (given below) to write the computeCoin function to work exactly as the the comments in the declaration below specify. The learning goals here are:
 
Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use a function that meets the following specifications. The idea is that you are being asked to write a specific function computeCoins, that is a general purpose function that when given a coin value coinValue (25, 10, or 1 in this case), and an amount of change remaining amountLeft, will return the quantity of that coin that should be given as change in the calbyreference parameter number, and will update the amount left in the callbyreference parameter amountLeft to be the amount left AFTER subtracting the number * coinValue quantity from the amountLeft.
 
Added:  
> >  //(CoinValue will always be 24, 10, or 1 for this project)  
//Postcondition: number has been set equal to the maximum number of coins of //denomination coinValue cents that can be obtained from amountLeft //amountLeft has been decreased by the value of the coins to be returned, that is,  
Line: 37 to 42  
%CODE{"c++"}% amountLeft = 37; computeCoins(25, number, amountLeft);  
Changed:  
< <  cout << Quarters to return:" << number << " with " << amountLeft << "cents remaining." << endl;  
> >  cout << "Quarters to return:" << number << " with " << amountLeft << "cents remaining." << endl;  
%ENDCODE%
The above sample code would return: 
Line: 1 to 1  

 
Line: 13 to 13  
Grading Table
 
Changed:  
< < 
 
> > 
 
 
Changed:  
< < 
 
> > 
 
Problem 1  Change Computation  
Changed:  
< <  Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use a function that meets the following specifications. The idea is that you are being asked to write a specific function computeCoins, that is a general purpose function that when give a coin value coinValue (25, 10, or 1 in this case), and an amount of change left amountLeft, will return the quantity of that coin that should be given in the change in reference parameter number, and will update the amount left in the reference parameter amountLeft be the amount left in change AFTER subtract the number * coinValue from the amountLeft.  
> >  Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use a function that meets the following specifications. The idea is that you are being asked to write a specific function computeCoins, that is a general purpose function that when given a coin value coinValue (25, 10, or 1 in this case), and an amount of change remaining amountLeft, will return the quantity of that coin that should be given as change in the calbyreference parameter number, and will update the amount left in the callbyreference parameter amountLeft to be the amount left AFTER subtracting the number * coinValue quantity from the amountLeft.  
Changed:  
< <  //Postcondition: number has been set equal to the maximum number of coins  
> >  //Postcondition: number has been set equal to the maximum number of coins of  
//denomination coinValue cents that can be obtained from amountLeft  
Changed:  
< <  //amountLeft has been decreased by the value of the coins, that is, //decreased by number*coinValue.  
> >  //amountLeft has been decreased by the value of the coins to be returned, that is, //amountLeft is decreased by number*coinValue.  
%ENDCODE%  
Changed:  
< <  For example, suppose the value of the variable amountLeft is 86 . Then, after the following call, the value of number will be 3 and the value of amountLeft will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents):  
> >  For example, suppose the value of the variable amountLeft is 86 . Then, after the following call, the value of number will be 3 (for 3 quaters) and the value of amountLeft will be 11 (because when you take 3 quarters from 86 cents, this leaves 11 cents):  
Line: 45 to 45  
Quarters to return: 1 with 12 cents remaining.  
Changed:  
< <  SO  once you have written a the function computeCoins, you will write a main program that uses computeCoins to figure out the change for an given amount. It will need to call computerCoins several times to do this correctly  
> >  So  once you have written the function computeCoins, you will write a main program that uses computeCoins to figure out the change for an given amount entered by the user. It will need to call computerCoins several times to do this correctly.  
Changed:  
< <  Include a loop in your program that lets the user repeat this computation for new input values until the user says he or she wants to end the program.
Functions  
> >  Note that computeCoins will NOT do any input or output (e.g. cin or cout). This will all be done in the main program.  
Changed:  
< <  Hint: Use integer division (/ operator) and the % operator to implement this function.  
> >  Include a loop in your program that lets the user repeat this computation for new input values until the user says he or she wants to end the program.
Hint
 
Sample runsEnter the amount of money between 1 and 99 cents: 62 
Line: 1 to 1  

 
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions  
Line: 84 to 85  
 
Added:  
> > 
 
 
Added:  
> > 
 

Line: 1 to 1  

 
Changed:  
< <  Lab 41  
> > 
 
Due: Oct 5, 11:55pm  
Changed:  
< <  Moodle Link  
> >  Moodle Link  
Instructions
 
Line: 13 to 15  
 
Changed:  
< < 
 
> > 
 
 
Line: 81 to 82  
Solutions  
Added:  
> > 
 

Line: 1 to 1  

 
Changed:  
< <  Lab 4  
> >  Lab 41  
Due: Oct 5, 11:55pm  
Line: 11 to 11  
Grading Table
 
Changed:  
< < 
 
> > 
 
Problem 1  Change Computation  
Line: 45 to 43  
Quarters to return: 1 with 12 cents remaining.  
Changed:  
< <  Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint: Use integer division (/ operator) and the % operator to implement this function.  
> >  Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program.
FunctionsHint: Use integer division (/ operator) and the % operator to implement this function.  
Sample runsEnter the amount of money between 1 and 99 cents: 62  
Line: 79 to 79  
 
Deleted:  
< <  Problem 2  Duel SimulationIn 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. Aaron 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 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the 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 turns starting with Aaron, followed by Bob, then by Charlie, then back to Aaron. The cycle would repeat until there was only one man standing. And that man would be remembered as the greatest puzzler of all time.
a. Write a function to simulate a single shot. It should use the following declaration:
< SyntaxHighlightingPlugin > void shoot(bool& targetAlive, double accuracy); < end SyntaxHighlightingPlugin > 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 . Below is a link that illustrates how to generate random numbers. Generating Random NumbersYou should write a function to seed the random number generator, and another to return the next random number between 0 and 1.
So, for example, if Bob is shooting at Charlie, this could be invoked as:
< SyntaxHighlightingPlugin > shoot(charlieAlive, 0.5); < end SyntaxHighlightingPlugin > Here, charlieAlive is a Boolean variable that indicates if Charlie is alive. Test your function using a driver program before moving on to step b. 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. The function will cycle through the men in the given order (Aaron, Bob, Charlie), dropping each men out of the conetest when they die. 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. For example, you might have the series:
What to doYou can either write two similar programs that use the different strategies, or you can write a single program with two versions of duel, e.g. duel1 (the first strategy) and duel2 (the second strategy), and have it first run the test with duel1, then with duel2. After each set of 1000 duels, print the probability that each contestant will win for that strategy. Example Run:
Strategy one: always shoot at the best shot. Out of a 1000 duels: Aaron wins 374 times, probability of winning 0.374 Bob wins 419 times, probability of winning 0.419 Charlie wins 207 times, probability of winning 0.207 Strategy two: always shoot at the best shot. Aaron misses first shot Out of a 1000 duels: Aaron wins 356 times, probability of winning 0.356 Bob wins 422 times, probability of winning 0.422 Charlie wins 222 times, probability of winning 0.222 (The above answers are examples, not the correct numbers). Turn In
 
Solutions

Line: 1 to 1  

Lab 4Due: Oct 5, 11:55pm  
Line: 122 to 123  
You can either write two similar programs that use the different strategies, or you can write a single program with two versions of duel, e.g. duel1 (the first strategy) and duel2 (the second strategy), and have it first run the test with duel1, then with duel2.  
Changed:  
< <  After each set of 1000 duels, print the probability that each contestant will win for that strategy:
Probability of winning with this strategy Charlie: 0.345 Bob: 0.255 Aaron: 0.4  
> >  After each set of 1000 duels, print the probability that each contestant will win for that strategy. Example Run:
Strategy one: always shoot at the best shot. Out of a 1000 duels: Aaron wins 374 times, probability of winning 0.374 Bob wins 419 times, probability of winning 0.419 Charlie wins 207 times, probability of winning 0.207 Strategy two: always shoot at the best shot. Aaron misses first shot Out of a 1000 duels: Aaron wins 356 times, probability of winning 0.356 Bob wins 422 times, probability of winning 0.422 Charlie wins 222 times, probability of winning 0.222  
(The above answers are examples, not the correct numbers). 
Line: 1 to 1  

Lab 4Due: Oct 5, 11:55pm  
Line: 91 to 90  
void shoot(bool& targetAlive, double accuracy); %ENDCODE%  
Changed:  
< <  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 . Appendix 4 illustrates how to generate random numbers.  
> >  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 . Below is a link that illustrates how to generate random numbers.
Generating Random NumbersYou should write a function to seed the random number generator, and another to return the next random number between 0 and 1.  
Changed:  
< <  For example, if Bob is shooting at Charlie, this could be invoked as:  
> >  So, for example, if Bob is shooting at Charlie, this could be invoked as:  
Line: 1 to 1  

Lab 4Due: Oct 5, 11:55pm  
Line: 8 to 8  
 
Deleted:  
< <  Grading  
Changed:  
< < 
 
> >  Grading Table
 
Problem 1  Change ComputationWrite a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use the following function (among others):  
Line: 124 to 129  
(The above answers are examples, not the correct numbers).  
Added:  
> >  Turn In
 
Solutions 
Line: 1 to 1  

Lab 4Due: Oct 5, 11:55pm  
Line: 35 to 35  
computeCoins(25, number, amountLeft); cout << Quarters to return:" << number << " with " << amountLeft << "cents remaining." << endl; %ENDCODE%  
Added:  
> >  
The above code would return:  
Changed:  
< <  Quarters to return: 1 with 12 cents remaining.  
> > 
Quarters to return: 1 with 12 cents remaining.  
Added:  
> >  
Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint: Use integer division (/ operator) and the % operator to implement this function.
Sample runs  
Line: 124 to 125  
(The above answers are examples, not the correct numbers).  
Added:  
> >  Solutions  

Line: 1 to 1  

Lab 4Due: Oct 5, 11:55pm  
Line: 17 to 17  
Problem 1  Change Computation  
Changed:  
< <  Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use the following function (among others): void compute_coin(int coin_value, int& number, int& amount_left);  
> >  Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use the following function (among others):  
Changed:  
< <  void compute_coin(int coin_value, int& number, int& amount_left); //Precondition: 0 < coin_value < 100; 0 <= amount_left < 100.  
> >  void computeCoins(int coinValue, int& number, int& amountLeft); //Precondition: 0 < coinValue < 100; 0 <= amountLeft < 100.  
//Postcondition: number has been set equal to the maximum number of coins  
Changed:  
< <  //denomination coin_value cents that can be obtained from amount_left //amount_left has been decreased by the value of the coins, that is, //decreased by number*coin_value.  
> >  //denomination coinValue cents that can be obtained from amountLeft //amountLeft has been decreased by the value of the coins, that is, //decreased by number*coinValue.  
%ENDCODE%  
Changed:  
< <  For example, suppose the value of the variable amount_left is 86 . Then, after the following call, the value of number will be 3 and the value of amount_left will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents): compute_coins(25, number, amount_left); Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint: Use integer division and the % operator to implement this function.  
> >  For example, suppose the value of the variable amountLeft is 86 . Then, after the following call, the value of number will be 3 and the value of amountLeft will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents):
< SyntaxHighlightingPlugin > amountLeft = 37; computeCoins(25, number, amountLeft); cout << Quarters to return:" << number << " with " << amountLeft << "cents remaining." << endl; < end SyntaxHighlightingPlugin > Quarters to return: 1 with 12 cents remaining.Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint: Use integer division (/ operator) and the % operator to implement this function.
Sample runsEnter the amount of money between 1 and 99 cents: 62 Quarters: 2 Dimes: 1 Pennies: 2 go again? (y to continue):y Enter the amount of money between 1 and 99 cents: 23 Quarters: 0 Dimes: 2 Pennies: 3 go again? (y to continue):y Enter the amount of money between 1 and 99 cents: 133 Amount must be between 1 and 99 cents Enter the amount of money between 1 and 99 cents: 45 Quarters: 1 Dimes: 2 Pennies: 0 go again? (y to continue):n  
Turn in Runs for:

Line: 1 to 1  

Lab 4  
Changed:  
< <  Due: Oct 4, 11:55pm  
> >  Due: Oct 5, 11:55pm  
Instructions

Line: 1 to 1  

Lab 4Due: Oct 4, 11:55pm  
Line: 13 to 13  
 
Changed:  
< <  Problem 1  
> >  Problem 1  Change Computation  
Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use the following function (among others): void compute_coin(int coin_value, int& number, int& amount_left);
 
Line: 36 to 36  
 
Changed:  
< <  Problem 2  
> >  Problem 2  Duel Simulation  
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. Aaron 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 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the person hit drops out of the duel.  
Changed:  
< <  To compensate for the inequities in their marksmanship skills, it is decided that the contestants would fire in turns starting with Aaron, followed by Bob, and then by Charlie. The cycle would repeat until there was one man standing. And that man would be remembered as the greatest puzzler of all time.  
> >  To compensate for the inequities in their marksmanship skills, it is decided that the contestants would fire in turns starting with Aaron, followed by Bob, then by Charlie, then back to Aaron. The cycle would repeat until there was only one man standing. And that man would be remembered as the greatest puzzler of all time.  
a. Write a function to simulate a single shot. It should use the following declaration:
 
Line: 56 to 56  
shoot(charlieAlive, 0.5); %ENDCODE%  
Changed:  
< <  Here, charlieAlive is a Boolean variable that indicates if Charlie is alive. Test your function using a driver program before moving on to step b.  
> >  Here, charlieAlive is a Boolean variable that indicates if Charlie is alive. Test your function using a driver program before moving on to step b.  
Changed:  
< <  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.  
> >  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. The function will cycle through the men in the given order (Aaron, Bob, Charlie), dropping each men out of the conetest when they die.  
Changed:  
< <  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.  
> >  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.  
Added:  
> >  For example, you might have the series:
 
d. A counterintuitive strategy is for Aaron to intentionally miss on his first shot. Thereafter, everyone uses the strategy of shooting at the most 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.
What to do  
Changed:  
< <  You can either write two similar programs that use the different strategies, or you can write a single program with two versions of duel, e.g. duel1 (the first strategy) and duel2 (the second strategy), and have it first run the test with duel1 , then with duel2 .  
> >  You can either write two similar programs that use the different strategies, or you can write a single program with two versions of duel, e.g. duel1 (the first strategy) and duel2 (the second strategy), and have it first run the test with duel1, then with duel2.  
Changed:  
< <  After each set of 1000 duels, print the probability that each contestant will win for that strategy:  
> >  After each set of 1000 duels, print the probability that each contestant will win for that strategy:  
Probability of winning with this strategy Charlie: 0.345 Bob: 0.255 
Line: 1 to 1  

Lab 4  
Changed:  
< <  Due: Oct 8, 11:55pm  
> >  Due: Oct 4, 11:55pm  
Instructions

Line: 1 to 1  

Lab 4Due: Oct 8, 11:55pm  
Line: 13 to 13  
 
Changed:  
< <  Problems  
> >  Problem 1  
Changed:  
< <  1. Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use the following function (among others): void compute_coin(int coin_value, int& number, int& amount_left);  
> >  Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use the following function (among others): void compute_coin(int coin_value, int& number, int& amount_left);  
 
Line: 28 to 28  
%ENDCODE%
For example, suppose the value of the variable amount_left is 86 . Then, after the following call, the value of number will be 3 and the value of amount_left will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents): compute_coins(25, number, amount_left); Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint: Use integer division and the % operator to implement this function.  
Added:  
> >  Turn in Runs for:  
Changed:  
< <  2. 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. Aaron 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 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the person hit drops out of the duel.  
> > 
Problem 2In 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. Aaron 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 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the 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 turns starting with Aaron, followed by Bob, and then by Charlie. The cycle would repeat until there was one man standing. And that man would be remembered as the greatest puzzler of all time.  
Line: 54 to 64  
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 most 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.  
Added:  
> >  What to do
You can either write two similar programs that use the different strategies, or you can write a single program with two versions of duel, e.g. After each set of 1000 duels, print the probability that each contestant will win for that strategy:
Probability of winning with this strategy Charlie: 0.345 Bob: 0.255 Aaron: 0.4 (The above answers are examples, not the correct numbers).  

Line: 1 to 1  

Lab 4  
Changed:  
< <  Due: Oct 7, 11:55pm  
> >  Due: Oct 8, 11:55pm  
Instructions

Line: 1 to 1  

Lab 4  
Changed:  
< <  Due: Oct 6, 11:55pm  
> >  Due: Oct 7, 11:55pm  
Instructions
 
Line: 29 to 29  
For example, suppose the value of the variable amount_left is 86 . Then, after the following call, the value of number will be 3 and the value of amount_left will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents): compute_coins(25, number, amount_left); Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint: Use integer division and the % operator to implement this function.  
Changed:  
< <  2. 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. Aaron 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 1/2. Charlie is an expert marksman and never
misses. A hit means a kill and the 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 turns starting with Aaron, followed by Bob, and then by Charlie. The cycle would repeat until there was one man standing. And that man would be remembered as the greatest puzzler of all time.  
> >  2. 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. Aaron 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 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the person hit drops out of the duel.  
Changed:  
< <  a. Write a function to simulate a single shot. It should use the following declaration:  
> >  To compensate for the inequities in their marksmanship skills, it is decided that the contestants would fire in turns starting with Aaron, followed by Bob, and then by Charlie. The cycle would repeat until there was one man standing. And that man would be remembered as the greatest puzzler of all time.
a. Write a function to simulate a single shot. It should use the following declaration:  
< SyntaxHighlightingPlugin > void shoot(bool& targetAlive, double accuracy); < end SyntaxHighlightingPlugin >  
Changed:  
< <  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 . Appendix 4 illustrates how to generate random numbers.  
> >  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 . Appendix 4 illustrates how to generate random numbers.  
For example, if Bob is shooting at Charlie, this could be invoked as:
< SyntaxHighlightingPlugin > shoot(charlieAlive, 0.5); < end SyntaxHighlightingPlugin >  
Changed:  
< <  Here, charlieAlive is a Boolean variable that indicates if Charlie is
alive. Test your function using a driver program before moving on to
step 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 most 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.  
> > 
Here, charlieAlive is a Boolean variable that indicates if Charlie is alive. Test your function using a driver program before moving on to step 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 most 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.  

Line: 1 to 1  

Lab 4Due: Oct 6, 11:55pm  
Line: 83 to 83  
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.  
Added:  
> > 

Line: 1 to 1  

Added:  
> > 
Lab 4Due: Oct 6, 11:55pmInstructions
Grading
Problems1. Write a program that tells what coins to give out for any amount of change from 1 cent to 99 cents. For example, if the amount is 86 cents, the output would be something like the following: 86 cents can be given as 3 quarter(s) 1 dime(s) and 1 penny(pennies) Use coin denominations of 25 cents (quarters), 10 cents (dimes), and 1 cent (pennies). Do not use nickel and halfdollar coins. Your program will use the following function (among others): void compute_coin(int coin_value, int& number, int& amount_left);
< SyntaxHighlightingPlugin > void compute_coin(int coin_value, int& number, int& amount_left); //Precondition: 0 < coin_value < 100; 0 <= amount_left < 100. //Postcondition: number has been set equal to the maximum number of coins //denomination coin_value cents that can be obtained from amount_left //amount_left has been decreased by the value of the coins, that is, //decreased by number*coin_value. < end SyntaxHighlightingPlugin > For example, suppose the value of the variable amount_left is 86 . Then, after the following call, the value of number will be 3 and the value of amount_left will be 11 (because if you take 3 quarters from 86 cents, that leaves 11 cents): compute_coins(25, number, amount_left); Include a loop that lets the user repeat this computation for new input values until the user says he or she wants to end the program. Hint: Use integer division and the % operator to implement this function. 2. 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. Aaron 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 1/2. Charlie is an expert marksman and never misses. A hit means a kill and the 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 turns starting with Aaron, followed by Bob, and then by Charlie. The cycle would repeat until there was one man standing. And that man would be remembered as the greatest puzzler of all time.
a. Write a function to simulate a single shot. It should use the following
declaration:
< SyntaxHighlightingPlugin > void shoot(bool& targetAlive, double accuracy); < end SyntaxHighlightingPlugin >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 . Appendix 4 illustrates how to generate random numbers.
For example, if Bob is shooting at Charlie, this could be invoked as:
< SyntaxHighlightingPlugin > shoot(charlieAlive, 0.5); < end SyntaxHighlightingPlugin >Here, charlieAlive is a Boolean variable that indicates if Charlie is alive. Test your function using a driver program before moving on to step 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 most 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. 