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: 3682904 • 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

# include <iostream>
# include <cmath>
# include <string>
using namespace std;
void fallingDistance2(double &);
double fallingDistance1(double);
const double g = 9.8;
int t;
double d;
int main()
{
cout<<"calculated by passby values. ";
cout<<"Time Distance ";
cout<<"------------------- ";
for (t=1;t<=10;t++)
{
fallingDistance1(d);
cout<<t<<" "<<d<<endl;
}
cout<<"calculated by reference values. ";
cout<<"Time Distance ";
cout<<"------------------- ";
for (t=1;t<=10;t++)
{
fallingDistance2(d);
cout<<t<<" "<<d<<endl;
}
return 0;
}
double fallingDistance1(double d)
{
d=0.5*9.8*t*t;
return d;
}
void fallingDistance2(double &refd)
{
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