Question

In: Computer Science

Write a C++ program, falling.cpp, that inputs a distance in meters from the user and computes...

Write a C++ program, falling.cpp, that inputs a distance in meters from the user and computes the amount of time for the object falling from that distance to hit the ground and the velocity of the object just before impact. Air resistance is discounted (assumed to fall in a vacuum).

To compute the time, use the formula: t = Square Root (2d / g)

where d is the distance in meters and g is the acceleration due to gravity on earth (use 9.807 meters/sec2). The time is measured in seconds.

To compute the velocity, use the formula:
v = Square Root (2dg)
The velocity is measured in meters per second.

You are required to write the following functions:

// Computes the amount of time for an object to fall to the // ground given the distance to fall as a parameter. The // time is returned (computeTime does not print anything). double computeTime (double distance);

// Computes the final velocity of an object falling to the // ground given the distance to fall as a parameter. The // velocity is returned (computeVelocity does not print // anything).

double computeVelocity (double distance);

// print prints its three parameters with labels.
// Print does not return a value.
void print (double distance, double time, double velocity);

Sample run:

Enter the distance: 100

Distance: 100.00 meters Time: 4.52 seconds
Velocity: 44.29 meters/second

Double values should be printed with two digits after the decimal.

Solutions

Expert Solution

Please comment, if you need any corrections.Please give a Thumps up if you like the answer.

Program

#include <iostream>
#include <cmath>
#include <iomanip>
#define g 9.807
using namespace std;

double computeTime (double distance);
double computeVelocity (double distance);
void print (double distance, double time, double velocity);

int main()
{
   double distance,time,velocity;
   cout<<"Enter distance in meters: ";
   cin>>distance;
   time=computeTime(distance);  
   velocity=computeVelocity (distance);
   print (distance,time,velocity);
   return 0;
}

double computeTime (double distance)
{
   double time;
   time = sqrt(2*distance / g);
   return(time);
}

double computeVelocity (double distance)
{
   double velocity;
   velocity = sqrt(2*distance*g);
   return(velocity);
}

void print (double distance, double time, double velocity)
{
   cout << fixed << showpoint;
   cout << setprecision(2);  
   cout<<"Distance: "<<distance<<" meters Time: "<<time <<" seconds"<<endl;
   cout<<"Velocity: "<<velocity<<" meters/second"<<endl;
}

Output

Enter distance in meters: 100
Distance: 100.00 meters Time: 4.52 seconds
Velocity: 44.29 meters/second


Related Solutions

Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that inputs a sequence of integers into a vector, computes the average,...
Write a C++ program that inputs a sequence of integers into a vector, computes the average, and then outputs the # of input values, the average, and the values themselves. There are 0 or more inputs values, followed by a negative value as the sentinel; the negative value is not stored and not counted. The following sample input: 10 20 0 99 -1 would produce the following output: N: 4 Avg: 32.25 10 20 0 99 The main program has...
Write a C++ program that requires the user to type in an integer M and computes...
Write a C++ program that requires the user to type in an integer M and computes the function y(M) which is defined by y(0)=2, y(1)=1, y(m+1)=y(m)+2*y(m-1).
Using Python Write a GUI program that converts a distance in Meters to the equivalent distance...
Using Python Write a GUI program that converts a distance in Meters to the equivalent distance in Feet. The user should be able to enter a distance in Meters, click a button, and then see the equivalent distance in feet. Use the following formula to make the conversion: Meters = Feet x 0.304 For example, 1 Meter is 3.28 Feet.
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a...
C++ program Overloaded Hospital Write a c++ program that computes and displays the charges for a patient’s hospital stay. First, the program should ask if the patient was admitted as an inpatient or an outpatient. If the patient was an inpatient, the following data should be entered: The number of days spent in the hospital The daily rate Hospital medication charges Charges for hospital services (lab tests, etc.) The program should ask for the following data if the patient was...
Write a program that asks the user to enter 3 grades and computes the minimum and...
Write a program that asks the user to enter 3 grades and computes the minimum and the maximum of those 3 grades and prints it. Hint: Use the Math.min() and Math.max() methods. This program will compute the smallest and highest of 3 grades entered by the user. Enter 3 grades separated by a space: 100 85.3 90.5 Smallest: 85.3 Highest: 100.0 Bye
IN JAVA: Write a simple program that takes 5 inputs from the user and save them...
IN JAVA: Write a simple program that takes 5 inputs from the user and save them into a Text File. The inputs are Student Name, Student Address and student Date of Birth. Also write a simple program that reads and display the input from the first program text file.
Write a program, Lab02_Q4.py, that inputs a string from the user, and creates a new string...
Write a program, Lab02_Q4.py, that inputs a string from the user, and creates a new string that deletes each non-alphanumeric character in the original string. You should solve this problem in 2 ways, first use a for loop that iterates through each character in the string, the second should use a while loop that iterates through a range. Keep spaces in the new string also. Hint: You can invoke the isalnum() function on a character, and it will return True...
Write a c++ program that inputs a time from the console. The time should be in...
Write a c++ program that inputs a time from the console. The time should be in the format “HH:MM AM” or “HH:MM PM”. Hours may be one or two digits. Your program should then convert the time into a four-digit military time based on a 24-hour clock. Code: #include <iostream> #include <iomanip> #include <string> using namespace std; int main() { string input; cout << "Enter (HH:MM XX) format time: "; getline(cin, input); int h, m; bool am; int len =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT