C++ REVIEW PROBLEMS Problem 1 – Change calculator (10 points) Define a function named change_calc that expects, as int values in this exact order, a number of quarters, a number of dimes, a number of nickels, and a number of pennies. It should return the sum total of all the coins in dollars and cents (for example, nine quarters, a dime, two nickels and a penny should return 2.46). Submit files named change_calc.cpp and change_calc.h that contain the appropriate code, and your main.cpp should contain at least two tests of the function. Be sure to test for approximate values of the correct answer, as double amounts can sometimes be not exact! Problem 2 – Metric to English units conversion (10 points) A metric ton is 35,273.92 ounces. Define a function named mton_to_ounce that asks the user to enter a weight in metric tons and prints to the screen the same weight in ounces. The function should continue to ask the user to enter values until a value less than or equal to 0 is entered, then the function should exit. Submit files named mton_to_ounce.cpp and mton_to_ounce.h that contains the appropriate code, including the code that repeats the question to the user until a non-positive value Is entered. Your main.cpp should contain only a single call to mton_to_ounce, and you should test the function by running the code until you are satisfied it works. Problem 3 – Prime number calculator (15 points) Write a program named prime_generator that asks the user to enter a positive integer, then determine and prints to a file named primes.txt all the prime numbers from 2 to the given number. This primality calculation must be done using an algorithm (and not simply read from an array of pre-determined prime numbers). Your code does not need to be efficient, and may use a doubly-nested loop – an outer loop that counts from 2 to the number the user enters, and an inner loop from 2 to the value being tested where divisibility is determined. Humboldt State University – CS 112 Fall 2020 – Assignment #1 p. 2 of 3 Problem 4 – Rock-Paper-Scissors Game (15 points) NOTE: You will need to have the statement #include in the "include" section of the CPP file! Write a function named rochambeau (another name for this game) that will play the Rock-Paper-Scissors game interactively with the user for as many times as the user wishes to play. Within a loop, the user should be asked for an R, P, or S, either lower or upper case, while any other letter will end the game and report the score (the number of user wins, user losses, and ties). In each round, the computer gets the user value, then generates its own move of Rock, Paper, or Scissors. Rock defeats Scissors, Scissors defeats Paper, and Paper defeats Rock. If the user and the computer choose the same item, it's a tie. Each round should display what the computer chose and the result (User Wins, User Loses, or Tie). Your C++ code can make use of the rand() function builtin to the cmath library. A call to a function called srand may be necessary to "seed" the random number generator (this can vary in different IDEs!). In NetBeans, a single use of the statement srand(time(NULL)); seeds the generator, then each call to rand() generates a random integer from 0 to 32,767. The expression rand() % 3 will make a random value of 0, 1, or 2. Submit files named rochambeau.cpp and rochambeau.h that contains the appropriate code, including the code that repeats the game until the user exits. Your main.cpp should contain only a single call to rochambeau, and you should test the function by running the code until you are satisfied it works. Problem 5 – Player Duel (50 points) Aaron, Bob and Charlie had an argument over which one of them was the greatest sharpshooter of all time. To end the argument once and for all, they challenged each other to a duel – with water pistols, of course! Aaron is a poor shooter and only hits his target with a probability of 1/4. Bob is a bit better and hits his target with probability of 1 / 2. Charlie is an expert and hits the target with a probability of 3/4. (HINT: Code up the same random number generator as in Problem 4, and you can use rand() % 12 to generate any of 12 different random values from 0 to 11. You can use this to generate values to figure out whether a player has hit their targets!) A hit means the person who is hit drops out of the duel. To compensate for the differences in their sharpshooting skills, it is decided that the contestants will fire in turns, starting with Aaron, followed by Bob and then by Charlie. The cycle repeats until there is only one standing. Once a player is out, of course, that player shouldn't get any more turns. (a) Define a function to simulate a single shot at a target. It should use the following header: void shoot(bool& targetActive, double accuracy); The parameter targetActive will pass BY REFERENCE the status of the target – if the target is no longer active (that is, been shot and out of the duel) then targetActive will be false, otherwise targetActive will be true. The function will simulate someone shooting at the given target (if that target is still targetActive) with the given accuracy of the one doing the shooting. The function will generate a random value (as explained above). For example, if accuracy is set to 0.5, then a random integer value from 0 to 5 can represent a hit, while a random value from 6 to 11 and represent a miss. If a hit is registered, targetActive is to be set to false, otherwise targetActive keeps its current value. Humboldt State University – CS 112 Fall 2020 – Assignment #1 p. 3 of 3 Your main() function will use bool variables aaronActive, bobActive, and charlieActive to keep track of the three shooters. All should be set to true before the duels begin. TIP: set defined constant values for the accuracies of Aaron, Bob, and Charlie, and use those constants. Suppose we call those AARON_ACCURACY, BOB_ACCURACY, and CHARLIE_ACCURACY. Then, for example, if Bob is shooting at Charlie, this could be invoked as: shoot(charlieActive, BOB_ACCURACY); NOTE that's it's Bob's shooting accuracy that is pass in the function, as Bob is doing the shooting. Test your function thoroughly before moving to the next part. (b) Now that you have a function that shoots another character, An obvious strategy is for each player to shoot at the most accurate shooter still active, since that player has the best chance of hitting back. Define a function named start_duel that uses the shoot function to simulate an entire duel using this strategy. It should loop until only one player 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 of some type that indicates who won the duel. (c) In your main() function, invoke the start_duel function 1000 times in a loop, keeping track of how many times each player won the duel. Output the stats of each player with the duels won after the 1000 duels.