Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C language This program will be a battleship simulator. You are the commander of a battleship who needs to know where the enemy is

In C language

This program will be a battleship simulator. You are the commander of a battleship who needs to know where the enemy is at in order to fire on them. Our radar has detected many other enemy battleships off our bow and the distance from the starboard side of our ship is stored in a text file whose name is given via a command line argument. This text file will contain an indeterminate amount of ships so you'll have to continue to parse and evalutate for each ship until end-of-file. We'll be firing upon these ships with our canons which means we'll have to use some ballistic equations to determine at what angle our cannon needs to fire at. Our canons fire with an initial velocity of 70 m/s and the furthest distance they can hit a target is 500m. This is due to this equation: d = Vo^2sin(2)/g. where Vo is our initial velocity of 70 m/s and g is the gravitational acceleration of 9.8 m/s^2. We'll need to determine the angle, , with which we need to fire our canon relative to the ground in order to hit the target. Use a precision of 2 decimal places when you print the final answer.

input file: 100 50 25 output: : 5.77 : 2.87 : 1.43 

We get this answer using the following formula from the linked wikipedia article below: d = Vo^2sin(2)/g

Where d is given to us via each line in the file, Our initial velocity, Vo, is stated in the prompt to be 70 m/s, and the gravitational constant, g, is 9.8 m/s^2. So we just need to solve for Theta, . Via algebra, we get this: = (arcsin((distance x 9.8)/70^2)/2) x 180/PI . You'll have to use asin from the math.h library, but remember it returns an answer in radians so you''ll need to multiply the final result by 180/pi. copy and paste this below your header files to define a constant for PI: #define PI 3.14159265

for instance 5.77 = (arcsin((100 x 9.8)/70^2)/2) x 180/pi

The math.h library has double asin(double) and double pow(double base, double pow).

Pic of Battleship

Here is an a graphic illustrating some of the physics behind projectile motion: Physics of a Projectile

Wikipedia/Projectile Motion

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

c. What groups were least represented? Why do you think this is so?

Answered: 1 week ago

Question

7. Describe phases of multicultural identity development.

Answered: 1 week ago