Comp Sci What are the stages and times of the rocket's flight?

  • Thread starter Thread starter Lord Dark
  • Start date Start date
  • Tags Tags
    C++ Rockets
AI Thread Summary
The discussion focuses on programming a solution to analyze rocket flight data stored in a file named rocket3.dat. Key tasks include reading the data, writing results to output.dat, and determining the timing of rocket stage firings based on velocity and acceleration changes. The user has successfully implemented parts of the program but struggles with identifying the correct times for stage firings, specifically when acceleration transitions from negative to positive. Suggestions include tracking the sign of acceleration values to detect these transitions effectively. The user ultimately resolves their coding issue with guidance from forum members.
Lord Dark
Messages
120
Reaction score
0
Hi guys,

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

  • Output.jpg
    Output.jpg
    74.1 KB · Views: 531
  • rocket3.txt
    rocket3.txt
    1.5 KB · Views: 427
Last edited:
Physics news on Phys.org
guys I've got an idea but I don't know how to do it ,,

I want to say when the acceleration goes from negative to positive record the time ,, but how can I say that in codes ??
 
Either remember sign of the last value in additional variable and go for (lastsignnegative && a > 0), or read all in the table and compare signs of neighboring values by something like (a < 0 && a[i+1] > 0). This is not bulletproof as if at some point a is zero you will probably miss it.
 
thanks Borek, but I don't know how to assign (lastsignnegative) to the last negative value and in the second way how to assign it in my code ?? i mean how to assign it to values of a if a is the acceleration and you've typed a(i) write it as a(a) ??
 
Last edited:
thanks borek ,, I've got you now :) ,, solved :D thanks again
 

Similar threads

Replies
8
Views
1K
Replies
3
Views
2K
Replies
9
Views
3K
Replies
6
Views
3K
Replies
17
Views
2K
Replies
15
Views
2K
Replies
1
Views
2K
Replies
14
Views
3K
Replies
3
Views
2K
Back
Top