Could somebody please, how to write this c++ program? When a projectile is launc
ID: 3830905 • Letter: C
Question
Could somebody please, how to write this c++ program?
When a projectile is launched straight up, its height at seconds after launch can be calculated with the following formula, where v_o is the velocity in meters per second at launch time (time 0), t is time in seconds, and g is the constant for gravitational acceleration on earth (9.80665). height = v_o t - 1/2gt^2 Create a program that calculates and outputs to file charts of the time it takes various projectiles of different input velocities to return to earth. a) ask the user to input the name for the output file b) loop and ask the user to enter velocities in meters/second for a projectile at time 0 c) for each velocity, output a header indicating the launch velocity and following that, write a table to a file that shows the height of the projectile from time 0 until it returns to earth, showing the final height as 0. For example, a table for a launch velocity of 60 m/s would look like this: 0 0 1 55.097 2 100.387 3 135.870 4 161.547 5 177.417 6 183.480 7 179.737 8 166.187 9 142.831 10 109.668 11 66.698 12 13.921 13 0 d) the launch velocity should be output as a heading for each chart, and all output should be neatly formatted in columns with heading e) cease processing when indicated by the userExplanation / Answer
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main(){
double velocity;
char fileName[20];
cout << fixed << setprecision(1);
cout << "Enter a projectile velocity in m/s and a file name for the results: ";
cin >> velocity;
cin >> fileName;
ofstream outFile(fileName);
double height = 0.0;
outFile << "Time (seconds) Height (meters) ";
int t = 0;
do{
outFile << setw(6) << t++ << setw(20) << height << " ";
height = velocity * t - 0.5 * 9.8 *t *t;
}while(height >= 0);
outFile << setw(6) << t++ << setw(20) << 0 << " ";
outFile.close();
}