Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ *please do not handwrite* The velocity of a falling object dropped from a re

ID: 3593749 • Letter: C

Question

C++ *please do not handwrite*

The velocity of a falling object dropped from a resting position is found using the following equation: v=gt

where: v is the velocity in meters per second

g is the acceleration of gravity (9.8 m/s^2)

t is the time since the object was dropped, in seconds

The distance traveled by the falling object is found using the equation: d=(1/2)gt^2

Where: d = is the distance traveled in meters

g is the acceleration of gravity (9.8 m/s^2)

t is the time since the object was dropped in seconds

Write a complete program that accepts input of time since the object was dropped and determines the velocity and distance traveled. display the time, velocity, and distance at the end of the program. To test your program, execute the program using time =1.5 sec, and then execute it again using time=4 sec.

Explanation / Answer

#include <iostream>

#include <stdlib.h>

using namespace std;

#define G 9.8 //Constant Gravity

int main()

{

float time;

//If input is negative or not in proper format, it will run indefinitely

while(true){

    char input[10];

    cout << "input of time since the object was dropped : ";

    cin >> input;

    // atof function converts char array to float.

    if(atof(input)<=0){

        cout << "Please provide valid Time." << endl;

        continue;

    }

    time = atof(input);

    break;

}

//Calculate velocity

float velocity = G * time;

cout << "Velocity of object : " << velocity << "m/s"

<<endl ;

//Calculate distance

float distance = 0.5 * G * time * time ;

cout << "Distance traveled by the falling object : " << distance << "m" << endl;

return 0;

}

+++++++++++++++++++

Sample output :

input of time since the object was dropped : 1.5
Velocity of object : 14.7m/s
Distance traveled by the falling object : 11.025m

-----------------------------------------------

input of time since the object was dropped : 4
Velocity of object : 39.2m/s
Distance traveled by the falling object : 78.4m

Hope it helps.

Happy Learning