Write a program in C++ A computer-games producer wants to simulate an archery co
ID: 3549500 • Letter: W
Question
Write a program in C++
A computer-games producer wants to simulate an archery contest. The target consist of a circle inscribed in an square, with a smaller concentric circle insisde. there are 4 archery contestants, and each gets 10 tries to shoot at the target.
The square is 2 feet on a side. The radius of the large circle is 1 foot; the radius of the small circle is 0.5 foot. if the arrow lands inside the small circle, the archer gets 2 points. if the arrow lands outside the small circle but inside the large circle, the archer gets 1 point. if the arrow lands outside the large circle, the archer gets 0 points.
consider the center of the target as the origin on an x, y graph. The result of one shot is given by the x,y coordinates where it hit. So 0.46, -0.11 would mean the arrow hit in the right hand half of the target, but down in the lower right quadrant. (x=0.46, y=-0.11). statments in your program are to determine what score that should receive.
Read the data from the data supplied. Each row of data file supplied. Each row of data is one archer's 10 tries. Each pair of numbers is one set of coordinates. So -0.69 -0.98 means the first hit was at x=-0.69 and y=-0.98. The next two numbers, 0.46 -0.11 means the second hit was at x=0.46 and y=-0.11, etc.
Use a loop that will handle one archer's 10 tries and print out on the screen that archer's total score.
Use another loop that will repeat this process for all 4 archers.
-0.69 -0.98 0.46 -0.11 0.77 -0.11 0.35 -0.94 -0.87 -0.49 -0.08 -0.21 -0.1 -0.43 -0.92 0.22 0.58 -0.45 0.29 0.26
-0.78 -0.39 0.9 -0.66 -0.66 0.49 -0.29 -0.4 0.22 -0.78 -0.61 -0.71 -0.3 -0.03 -0.14 -0.85 0.63 -0.94 -0.69 0.8
-0.67 0.32 0.86 0.21 -0.87 -0.16 -0.94 0.87 -0.36 0.28 -0.88 -0.87 0.46 0.9 -0.43 -0.32 0.95 -0.1 -0.1 0.91
0.64 0.14 0.33 0.04 -0.82 -0.41 0.65 0.46 0.35 0.84 -0.42 0.27 0.64 0.62 -0.96 0.88 -0.2 0.35 -0.88 -0.14
Explanation / Answer
#include <iostream.h>
#include <math.h>
using namespace std;
int calculate_point ( float , float );
int point = 0 ;
int main ()
{
int i = 0;
int tmp = 0;
float x , y;
while( i <= 9 )
{
cout<< " enter the value for x coordinate and y coordinate respectively for " << i+1 << " shot taken";
cin>>x;
cin>>y;
tmp = calculate_pont(x , y );
point = point + tmp;
i++;
}
cout << " the net point is "<<point;
}
int calculate_point( float x , float y)
{
float d = 0.0;
d = { (x-0)*(x-0) + (y-0) * (y-0) } ^0.5;
if ( d <= 0.5 )
return 2;
else if ( d > 0.5 && d <= 1.0 )
return 1;
else
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.