rocket performance table

how do I get my program to print out a table showing the rockets altitude and velocity for each 0.1 second of the flight. the table ends when the rocket reaches its apogee(highest point) I know I need to use a loop like a while loop but how do I use it.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
using namespace std;

int main()
{
	double mass_rock,
		   mass_engine,
		   mass_propellant,
		   engine_thrust,
		   engineburn_duration,
		   max_velocity,
		   max_altitude,
		   acceleration,
		   masskilo,
		   height1,
		   height2;
	double const time = .5;

	// Output Identification
	system("CLS");
	cout << "In Class #6 - "
		 << " rocket performance table\n\n";

	cout << "Enter the mass of the rocket (grams): ";
	cin >> mass_rock;

	cout << "Enter the mass of the engine (grams): ";
	cin >> mass_engine;

	cout << "Enter the mass of the propellant (grams): ";
	cin >> mass_propellant;

	cout << "Enter the average thrust of the engine (newtons): ";
	cin >> engine_thrust;

	cout << "Enter the burn duration of the engine (seconds): ";
	cin >> engineburn_duration;

	masskilo = (mass_engine + mass_rock + mass_propellant) / 1000;

	acceleration = engine_thrust /(masskilo/2);

	max_velocity = acceleration * time;

	height1 = 1/2 * max_velocity * time * time;

	height2 = (max_velocity * max_velocity)/(2 * 9.8);

	max_altitude  = height1 + height2;

	

	return 0;
}[
u][/u]
Last edited on
Could you please put your code between code blocks? You can see it under "format" to the right.
Done sorry about that.
closed account (D80DSL3A)
You will need formulas for the velocity and height as functions of the time during 2 time periods.
Period 1 is while the engine is firing: 0 to engineburn_duration
Period 2 is while the rocket is coasting: engineburn_duration until velocity=0.

The equations in your code don't seem to quite fit this need.
Can you post the actual equations that you've been given to work with?

Last edited on
Rocket performance Table

the program will ask the user for the mass of the rocket without the engine, the mass of the engine, the mass of the propellant in the engine, the engines average thrust and the burn duration of the engine. The program will then print out a table showing the rockets altitude & velocity for each 0.1 sec of the flight. The table ends when the rocket reaches its high point. The program will assume the rocket flight is straight up and will ignore the effects of aerodynamic drag.
The calculation needs to be done in two parts, the powered flight and the non-powered flight. for the powered flight assume the mass of the rocket is a constant value (use average mass.

equations: distance = initial_distance + velocity * time,

velocity = initial_velocity = acceleration * time,

distance = initial_distance + initial_velocity * time + 1/2 * acceleration * time^2,

force = mass * acceleration,

gravity = 9.8m/s^2

example output:
mass rocket = 23g
mass engine = 16.2g
mass propellant = 3.12g
average thrust = 8 newtons
burn duration = 0.5
closed account (D80DSL3A)
That makes better sense.
The 1st equation doesn't look useful, as it applies only when acceleration = 0. The acceleration is non zero at all times during the flight. It's > 0 during the burn and -9.8 afterward.
In the 2nd equation the 2nd = should be +.

The directions say use the average mass during the burn phase, so use:
mass = mass rocket + mass engine + 0.5*mass propellant;

During the burn phase find acceleration from:
acceleration = net force/mass = (thrust - mass*gravity)/mass

You could do the table using 2 loops. 1st loop uses equations 2 and 3 for the burn phase. This is t=0 to t= burn duration.

Then, calculate velocity and distance at t = burn duration. These are the initial distance and velocity figures for the 2nd "freefall" phase.
Use equations 2,3 from t=0 again in the 2nd loop (display t + burn duration in the table though). It could either go until velocity becomes < 0, or until a calculated time. T calc = initial velocity/9.8. Either way should work.
Last edited on
Thank you for your help I've done small changes to the program but i still have problems with the calculations. The example output that i was given has a max velocity of 101.37 m/s and a max altitude of 549.621. my output is way off I really don't know what i'I'm doing wrong???

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
int main()
{
	double mass_rock,  // mass of rocket (grams)
		   mass_engine,  // mass of engine (grams)
		   mass_propellant,  // mass of propellant(grams)
		   engine_thrust,  // average thrust of engine (newtons)
		   burn_duration,  //burn duration of engine (seconds)
		   max_velocity,  // max velocity of rocket
		   max_altitude, // max altitude of rocket
		   acceleration,  // acceleration of rocket
		   height1,  
		   height2,
		   avg_mass;

	// Output Identification
	system("CLS");
	cout << " - "
		 << " rocket performance table\n\n";


	// ask user to enter mass of rocket
	cout << "Enter the mass of the rocket (grams): ";
	cin >> mass_rock;

	// ask user to enter mass engine
	cout << "Enter the mass of the engine (grams): ";
	cin >> mass_engine;

	// ask user to enter mass of propellant
	cout << "Enter the mass of the propellant (grams): ";
	cin >> mass_propellant;

	// ask user to enter average thrust of the engine
	cout << "Enter the average thrust of the engine (newtons): ";
	cin >> engine_thrust;

	// ask user to enter bburn duration in seconds
	cout << "Enter the burn duration of the engine (seconds): ";
	cin >> burn_duration;

	avg_mass = mass_rock + mass_engine + (burn_duration * mass_propellant);

	avg_mass = avg_mass / 1000;

	acceleration = (engine_thrust - avg_mass * 9.8) / avg_mass;

	max_velocity = acceleration * burn_duration;

	height1 = 1/2 * max_velocity * burn_duration * burn_duration;

	height2 = (max_velocity * max_velocity)/(2 * 9.8);

	max_altitude  = height1 + height2;

	cout << acceleration << endl;
	cout << max_altitude << endl;


closed account (D80DSL3A)
Are those figures for max velocity and max height expected for the sample output you gave in the previous post? If so, then I can't hit the numbers either.
I'm getting max vel = 93.2m/s and max height = 466.8m.

This means that I can't solve the problem.
Sorry that I can't help. Good luck!

EDIT: Two of the equations in your code differ from mine.
Line 41 avg_mass = mass_rock + mass_engine + (burn_duration * mass_propellant);
I used: avg_mass = mass_rock + mass_engine + 0.5* mass_propellant;
Though with burn_duration = 0.5 seconds these equations coincidentally give the same number.
I used that formula because the directions say "use average mass".

Line 49 height1 = 1/2 * max_velocity * burn_duration * burn_duration;
I used: height1 = 0.5 *acceleration * burn_duration * burn_duration;
This difference in formulas matters a lot.
Use 0.5 not 1/2. The rules for integer division make 1/2=0.You will get height1=0 because of that.
If you use the same formulas as I did you should at least get the closer, but still incorrect values.
Last edited on
If you want a table you need to use loops like fun2code mentioned, all you have here is sums and multiplications, no incremental values.

If you want a table for each 0.1 sec of the flight then that is the increment to use.

So maybe a loop say

do
{
cout << stuff << '\t' << stuff << '\t' << endl;
cout << morestuff << '\t' << ... << '\t' << endl;

t+0.1;

}
while(things are going up)

Like when the rocket has reached terminal velocity stop the loop.

Disclaimer: I never did much physics/mechanics and I'm a c++ newb.

Found this but I need to go

http://stackoverflow.com/questions/25591434/velocity-momentum-i-cant-go-the-distance

Good luck.
Last edited on
Topic archived. No new replies allowed.