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.
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?
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,
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.
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???
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;
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.