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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
// Include Section
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// This funtion computes the burnout altitude and the
// coast altitude of a model rocket.
// The first 6 parameter are the input data
// to the function. Parameter 7 and 8 return the results
void computeA( double massR, //Rocket Mass (g)
double massE, //Engine Mass (g)
double massP, //Propellant Mass (g)
double dia, //Diameter of Rocket (mm)
double advTh, //Adv thrust of Engine (N)
double burnD, //Burn Duration (s)
double& altB, //Burnout Altitude (m)
double& altC); //Coast Altitude (m)
// Main Program
int main( )
{
// Constant Declarations
const double a = 9.8;
const double pi = 3.14;
// Character Declarations
char runAgain;
// Variable Declarations
double massR; //Rocket Mass (g)
double massE; //Engine Mass (g)
double massP; //Propellant Mass (g)
double dia; //Diameter of Rocket (mm)
double advTh; //Adv thrust of Engine (N)
double burnD; //Burn Duration (s)
double altB; //Burnout Altitude (m)
double altC; //Coast Altitude (m)
double liftoffMass;
double coastPhaseMass;
double avgMass;
double k;
double A;
double burnVel;
// Output Identification
cout << "Take Home #8 - Rocket Altitudes. \n\n";
do
{
cout << " Enter the mass of the rocket in grams: ";
cin >> massR;
cout << " Enter the mass of the engine in grams: ";
cin >> massE;
cout << " Enter the mass of the propellant in grams: ";
cin >> massP;
cout << " Enter the diameter of the rocket in meters: ";
cin >> dia;
cout << " Enter the average thrust of the engine in newtons: ";
cin >> advTh;
cout << "Enter the burn duration of the engine in seconds: ";
cin >> burnD;
computeA( massR, massE, massP, dia, advTh, burnD, altB, altC);
A=pi*(dia/4000);
k=.05*1.2*0.75*A;
liftoffMass = (massR/1000) + (massE/1000); // liftoff mass of the vehicle
coastPhaseMass = (massR/1000) + (massE/1000) - (massP/1000); // mass during the coast phase
avgMass = (liftoffMass + coastPhaseMass) / 2; // average mass during the boost phase
burnVel = sqrt((advTh-avgMass*a)/k)*tanh((burnD/avgMass)*sqrt(k*(advTh-avgMass*a)));
cout << "\n The burnout altitude is " << altB << " meters.\n";
cout << " The coast altitude is " << altC << " meters.\n";
cout << " Do you want to run the program again? (y or n): ";
cin >> runAgain;
cout << "\n";
}
while (runAgain == 'y');
return 0;
}
void computeA( double massR,
double massE,
double massP,
double dia,
double advTh,
double burnD,
double& altB,
double& altC)
{
const double a = 9.8;
double k;
double avgMass;
double coastPhaseMass;
double burnVel;
altB = (avgMass/k)*log(cosh((burnD/avgMass)*sqrt(k*(advTh-avgMass*a))));
altC = (coastPhaseMass/(2*k))*log(((k*(burnVel*burnVel))/(coastPhaseMass*a))+1);
}
|