> C programming, computer genious genious help me more! T-T?

C programming, computer genious genious help me more! T-T?

Posted at: 2014-12-18 
There's a bit of basic calculus in this question.

If you don't recall, the position function s(t) is given by the integral of the integral of a(t) (the acceleration function).

The velocity function v(t) is the integral of a(t).

You're given v(0) = 0 so you can eliminate the indefinite constant term in v(t), and since you don't care about position, just distance, you can eliminate the indefinite constant in s(t) as well (set it to 0).

Remember, distance is (starting position - ending position), so the constant term will sum to 0.

The user inputs a constant acceleration, let's say a.

This means

a(t) = a

So the velocity of the car is given by:

v(t) = ∫ a * dt = at + C; v(0) = C = 0;

v(t) = at

and the speed is given by |v(t)|,

and the position function is

s(t) = ∫ at dt = (at^2)/2 + C

So if the user wrote that the car accelerated for 10 seconds at 9.8msec^-2, than

it traveled s(10) = (9.8(10)^2)/2 = 490 m

and it's speed is | v(10) | = 9.8(10) = 98 msec^-1

Note that velocity is a vector quantity, and in just one dimension, only sign is used to indicate direction. It is a higher-degree function and can be negative. Speed is a scalar quantity. That's the purpose of the absolute value.

Now onto the programming part:

Declare your functions

double GetSpeed (double Acceleration, double Seconds);

double GetDistance (double Acceleration, double Seconds);

You know that both acceleration and time are probably decimal values, so it would be prudent to accept those, as well as spit out a like-typed answer.

Now all that you need to do is return s(t) and v(t) from the appropriate function. Remember, you don't need to integrate on the fly, just substitute the real acceleration (the parameter) for the constant a in v(t), s(t).

Return the result and print.

Write a program that computes the speed and distance of a car given its acceleration and the elapsed time from the start. Assume the car was not moving at time zero.

Define a function GetSpeed(acc, t) that returns the speed after t-seconds. (acc: acceleration)

Hint) speed = acceleration * time

Define a function GetDistance(acc, t) that returns the distance.

Hint) distance = 0.5 * acceleration * time2

Write main()

Read acceleration and elapsed time.

Compute the speed and distance of the car.

Print the results

Ex) Input the acceleration and time of a car: 9.8 10

speed = 98.00, distance = 490.00