Hello, Can someone please assist me with this assignment. I am writing in C++ la
ID: 3831775 • Letter: H
Question
Hello, Can someone please assist me with this assignment. I am writing in C++ language. I would like some help please to end this semester very well.
Thank you so much in advance.
When a projectile is launched straight up, its height at seconds after launch can be calculated with the following formula, where vois the velocity at launch time (time 0), t is time in seconds, and g is a gravitational constant. height vot gt Create a program that a) asks a user to input a launch velocity in meters per second b) asks a user to input the name for the output file c) in neat columns, writes a table to a file that shows the height ofthe projectile from time 0 until it returns to earth (height becomes 0), showing the final height as 0 For example, for this input: Enter a projectile velocity in m/s and a file name for the results: out 60.txt The file will show: out60.bxt Notepad File Edit Format View Help ime seconds) Height (meters 55.1 100.4 135.9 161.6 183.6 179.9 166.4 143.1 10 110 67.1 11 12 14.4 13Explanation / Answer
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
int main()
{
cout << "Enter a projectile velocity in m/s and a file name for the results:" << endl;
double velocity;
char filename[100];
cin >> velocity;
cin >> filename;
ofstream outfile(filename);
double height = 0;
int t = 0;
outfile << "Time (seconds) Height (meters)" << endl;
outfile << right;
outfile << setw(13);
outfile << right << setw(13) << t <<right << setw(13) << height << endl;
while(true)
{
t++;
height = velocity*t -0.5*9.8*(t*t);
if(height <= 0.00001)
height = 0;
outfile << right << setw(13) << t <<right << setw(13) << height << endl;
if(height <= 0.00001)
{
break;
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.