- #1
Lord Dark
- 121
- 0
Hi guys,
I've got the following question :
and he want's me to :
I wrote the following code :
I've solved part 1,2,4 .. but the problem is in part 3 which I don't understand what the question means (I tried by maximum and minimum the velocity and acceleration but I get the first time which is wrong ... now I need your help guys :)
I've uploaded the data files (rocket3.txt) and the final results (how it should be)
I've got the following question :
Assume that there is an information stored in a file named rocket3.dat and that each line
contains four values: time, altitude, velocity, and acceleration. Assume that the units are s, m, m/s, and m/s2
respectively.
(A new stage in the rocket life can be determined when the velocity increases to some peak and then begins decreasing. After each stage of the rocket is fired, the acceleration will initially increase and then decrease to -9.8 m/s2, which is downward acceleration due to gravity.)
and he want's me to :
Write a program that does each of the followings:
1. Reads the data file rocket3.dat
2. Generate a new output file output.dat and write the output of this program to this file
3. Determine the time that corresponds to the firing of each stage if any.
4. Find the times of the rocket flight during which acceleration is due only to gravity. Allow the acceleration to range within 5% of the value of gravity; if we assume that the gravity is -9.8 m/s2, then the range of acceleration of interest is between -10.29 m/s2 and -9.31 m/s2.
I wrote the following code :
/*
The following program ...
*/
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
using namespace std;
int main ()
{
double t, // declaring the time
al, // declaring the altitude
v, // declaring the velocity
a, // declaring the acceleration
min_v(9e3), // declaring the minimum velocity
min_a(9e2);
ifstream infile ; infile.open("rocket3.dat"); // declaring the data file and it's address
ofstream outfile ; outfile.open("output.txt") ; // declaring the file which our results will be in
if (infile.fail())
{
cout << "There is no file named rocket3 the program will terminate" << endl ;
return (-1);
}
outfile << showpoint << fixed << scientific ;
infile >> t >> al >> v >> a ;
while (infile)
{
if (v < min_v)
min_v = v ;
if (a < min_a && a > 0)
min_a = a ;
if (a > -10.29 && a < -9.31)
{
outfile << "Acceleration due to gravity only at time: " << t << endl ;
}
infile >> t >> al >> v >> a ;
}
if (v == min_v && a == min_a )
outfile << "Stage fired at " << t << endl ;
return 0;
}
I've solved part 1,2,4 .. but the problem is in part 3 which I don't understand what the question means (I tried by maximum and minimum the velocity and acceleration but I get the first time which is wrong ... now I need your help guys :)
I've uploaded the data files (rocket3.txt) and the final results (how it should be)
Attachments
Last edited: