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

  • Comp Sci
  • Thread starter Lord Dark
  • Start date
  • Tags
    C++ Rockets
In summary, the program reads the data file rocket3.dat, generates a new file output.dat, and writes the output to this file. It then determines the time that corresponds to the firing of each stage if any. It finds the times of the rocket flight during which acceleration is due only to gravity.
  • #1
Lord Dark
121
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: 480
  • rocket3.txt
    1.5 KB · Views: 378
Last edited:
Physics news on Phys.org
  • #2
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 ??
 
  • #3
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.
 
  • #4
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:
  • #5
thanks borek ,, I've got you now :) ,, solved :D thanks again
 

1. What is a sounding rocket?

A sounding rocket is a type of rocket that is used to conduct scientific experiments and collect data in the Earth's upper atmosphere or outer space. These rockets are typically smaller and less powerful than traditional space rockets, and are designed to collect data during short flights before returning to Earth.

2. How do scientists use c++ in sounding rocket development?

C++ is a programming language that is commonly used in the development of software for sounding rockets. Scientists use c++ to write code that controls the rocket's trajectory, collects and analyzes data, and communicates with ground stations. This allows for precise control and data collection during the rocket's flight.

3. Can c++ be used for both the rocket's hardware and software?

Yes, c++ can be used for both the hardware and software components of sounding rockets. For hardware, c++ can be used to program microcontrollers and other electronic components that control the rocket's physical systems. For software, c++ can be used to write the code that controls the rocket's flight and collects data.

4. Are there any challenges in using c++ for sounding rocket development?

Yes, there can be challenges in using c++ for sounding rocket development. Since these rockets operate in extreme environments, the code must be able to withstand high altitudes, extreme temperatures, and other factors that can affect the rocket's performance. Additionally, the code must be thoroughly tested and debugged to ensure reliability and accuracy.

5. Are there any advantages to using c++ in sounding rocket development?

Yes, there are several advantages to using c++ in sounding rocket development. C++ is a high-performance language that allows for precise control and data collection during the rocket's flight. It also has a wide range of libraries and tools that can be used to develop complex software systems for the rocket. Additionally, c++ is cross-platform, meaning it can be easily adapted for use on different operating systems and hardware platforms.

Similar threads

  • Introductory Physics Homework Help
Replies
2
Views
182
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
  • Classical Physics
Replies
17
Views
1K
  • Introductory Physics Homework Help
2
Replies
42
Views
3K
  • Introductory Physics Homework Help
Replies
10
Views
620
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
Replies
4
Views
2K
  • Special and General Relativity
Replies
33
Views
1K
  • Introductory Physics Homework Help
Replies
4
Views
1K
  • Introductory Physics Homework Help
Replies
5
Views
1K
Back
Top