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

C++ Program When an object is falling because of gravity, the following formula

ID: 3683510 • Letter: C

Question

C++ Program

When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specific time period.

d = ½ gt2

The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, that the object has been falling.

Create a class called fallingobject.

The class should have two constructors, one should assign 0 to the time, and the other should pass the time in when it is created.

The class should have member functions that will assign a value to time, return the time and distance. Also include an exception errors if the time is a negative number.

Explanation / Answer

Hi below i have written the code for your reference,

# include <iostream>

# include <cmath>

# include <string>

using namespace std;

void fallingDistance2(double &, double);

double fallingDistance1(double);

const double g = 9.8;

double t;

double d;

int main()

{

cout<<"calculated by passby values. ";

cout<<"Time Distance ";

cout<<"------------------- ";

for (t=1;t<=10;t++)

{

cout<<t<<" "<<fallingDistance1(t)<<endl;

}

cout<<"calculated by reference values. ";

cout<<"Time Distance ";

cout<<"------------------- ";

for (t=1;t<=10;t++)

{

fallingDistance2(d, t);

cout<<t<<" "<<d<<endl;

}

return 0;

}

double fallingDistance1(double t)

{

return 0.5*9.8*t*t;

}

void fallingDistance2(double &refd, double t)

{

refd=0.5*9.8*t*t;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote