Description
1 Overview You will develop and implement a program that simulates an archery target shooting game. The primary objective of this assignment is for students to gain experience in using: function decomposition to simplify implementing a program; and random number generation with the library functions rand, srand, and time.
2 Program The goal of the simulation is to shoot an arrow at a target consisting of three concentric circles as shown below:
Hitting the white region (the center) is worth 5 points; hitting the green region is worth 3 points; and hitting the red region is worth 1 point. 0 points for missing all the 3 regions.
Please notice that you are going develop “a game simulator”, not an actual game. So, we will not have a real player and the arrows to shoot.
Instead, your program will use a random number generator to determine where the arrows land. That is why we call this exercise as “a simulation”. We basically simulate what happens after a player shoots.
After each arrow is shot (that is after a random number is generated), your program displays a message describing the result. After each round (i.e., a set of 5 shootings) is completed, the total score for that round is displayed. In addition, you should ask the user if s/he wants to continue the simulation. The program continues the simulation as long as the user wants. At each round, the player shoots 5 arrows from different distances: 10, 20, 30, 40, and 50.
3 Functions We use functions to break a problem into smaller sub-problems. This reduces program complexity. In this assignment you are supposed to implement 4 distinct functions. main chance shoot play
The main function will be the driver of the program. You should create the loop that controls the rounds in the main function. After each iteration of the loop body, it should ask the player if s/he wants to continue. Please notice that you should start every iteration by calling the predefined functions srand and time. This will ensure that your simulator generates random numbers properly. However, please notice that you will generate the random number in the function chance.
Introduction to Computer Science 1
By Hakan Haberdar – hakan@haberdar.org
The header (i.e., function declaration) of the function chance should be as follows:
double chance();
The function chance simply returns a random value between 0.0 and 1.0.
The third function you need to develop is called shoot. This function takes the distance as an argument. It returns the score of the shooting by using the random value returned by the chance function and the distance based on the following table below.
distance score:5 score:3 score:1 score:0 10 0.0≤chance<0.50 0.50≤chance<0.90 0.90≤chance<0.95 0.95≤chance≤1.0 20 0.0≤chance<0.40 0.40≤chance<0.80 0.80≤chance<0.90 0.90≤chance≤1.0 30 0.0≤chance<0.30 0.30≤chance<0.60 0.60≤chance<0.75 0.75≤chance≤1.0 40 0.0≤chance<0.20 0.20≤chance<0.40 0.40≤chance<0.60 0.60≤chance≤1.0 50 0.0≤chance<0.10 0.10≤chance<0.20 0.20≤chance<0.45 0.45≤chance≤1.0
The header (i.e., function declaration) of the function shoot should be as follows:
double shoot(int distance);
The last function you will develop is the play function. The function play calls the function shoot, and it is responsible for calculating and displaying messages (please see the output below) for a single round (i.e., a set of 5 shootings). The header (i.e., function declaration) of the function play should be as follows:
void play();
Introduction to Computer Science 1
By Hakan Haberdar – hakan@haberdar.org
4 Sample Output Please notice that your output (scores/points) will probably be different because we use random values.
Welcome to Archery Shooting Simulator Round 1: Distance 10: 5 points, you are awesome! Distance 20: 1 points Distance 30: 0 points, what a shame! Distance 40: 3 points Distance 50: 5 points, you are awesome! ——————— Total Score:14 points
Enter 0 to exit, any other value to play again: 1
Round 2: Distance 10: 0 points, what a shame! Distance 20: 3 points Distance 30: 0 points, what a shame! Distance 40: 5 points, you are awesome! Distance 50: 3 points ——————— Total Score:11 points
Enter 0 to exit, any other value to play again: 0
Introduction to Computer Science 1
By Hakan Haberdar – hakan@haberdar.org
5 Grading
Your file name must be as follows: FirstNameLastNameID.cpp
A correct solution: worth 100 points
Deductions:
ERROR DEDUCTED POINTSP rogram cannot be compiled 40 Program terminates unexpectedly during runtime 40 User interface does not have required information 5 No prompt for entering invalid data 10 Code is not commented 10 Proper indentation is not used 20 Proper variable types are not used 5 Any missing function (chance, shoot, play) each 25 srand not called in the loop in the main properly 10 Time not called in the loop in the main properly 10 No looping mechanism is used in the main 20 Function chance cannot return random values properly 20 Function shoot cannot return score values properly 25 Function play cannot display the results properly 20
1. Feel free to discuss ideas and implementations with your classmates, however DO NOT share code.
2. If you have a question about the assignment, do not wait until the last minute to ask.
3. Normal deductions for late submissions will be in effect. Please see Assignment Guidelines.
4. ANY kind of cheating, will result in a grade of 0.