The Task

The range R(v0, a) of a projectile fired with initial velocity v0 at an angle a is given by:

Your task in this test is to write a function to calculate the range, then to produce a table of ranges for prescribed values of velocity v0 at an angle a and finally to write the table into a file.

NB the sin function in c++ assumes an argument in radians rather than degrees. The conversion is:

a (rad) =  a (deg) /180

or, in actual code, something like

a_rad = (M_PI * a_deg)/180.;

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Exercise 1. – worth 50%

This exercise involves the creation of a function structure within a program.


CalcRange(angle, velocity) etc.

6. Compile the code and run it using a test input of 20 degrees and 100 m/s. These values should return a range of 655 m

Recommended Answers

All 4 Replies

sorry dude, but this is just retarded. U want your test solved... ok, but firt get a fizics or mechanics book, get the formulas you require to calculate what you need and that's it. You just have to call a few function and add a couple of numbers. This is about programming not mechanics :|

tell that to my college. I agree, but this is a C++ assignment that i cannot do. thanks anyway.

i'm struggling to do the calc function.

I can do it all seperatly, but i need to do it with a calc function

i'm struggling to do the calc function.

I can do it all seperatly, but i need to do it with a calc function

Figure out the exact formula you need to have, what the exact inputs are, and what you want as output. You need to figure out the physics angle of this first and work it out on paper mathematically before you even think about trying to code it in C++. Presumably there is some physics formula or series of physics formulas that you need to derive or already have that solves this. Any formula has inputs and outputs. When you make the function, your inputs will be the parameters passed to the function and your output is going to be what is returned from the function. You could also use global constants for things that don't change (i.e. g, the gravitational acceleration constant, assuming you are ALLOWED to keep that as a constant). So first step, what assumptions can you make (i.e. flat earth, no wind resistance, constant gravitational acceleration, etc.), what do you need to know to solve it, and what are the formulas? Next step, work it out mathematically on paper. Final step, turn the math into a computer function.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.