code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
Terms of Agreement:
By using this code, you agree to the following terms...
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame.
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
/*
Author: Wilton Marranzini
Objective: solve for the value (Pt - P0)(known as compressible q) as a
function of altitude and Mach number. Here is how your program
should be structured.
*/
//---------------Header Files-----------
// ------------
#include
#include
//---------------Prototypes for Function
// s------------
float p_ambient(float altitude);//ambient pressure function.
float p_ratio(float mach); //pressure ration function.
//--------------Global Constant---------
// -------------
const float GAMMA = 1.4;//global const of GAMMA.
//----------------Main Function---------
// --------------
int main()
{
float mach_n; //for Mach number.
float altitude_n; // for altitude number.
float ambient;// for ambient function.
float ratio; // for ratio function
float subtraction;// of (Pt - P0)
int x;//Keeps screen open
cout<< "Please enter altitude in feet: \n";
cin>> altitude_n; //Storing
cout<< "Please enter Mach number: \n";
cin>> mach_n;//storing
ambient = p_ambient (altitude_n);//Calling p_ambient
ratio = p_ratio (mach_n);//Calling p_ratio
subtraction = (ambient * ratio) - ambient; //Computing (Pt-P0)
cout<< "At an altitude of "<< altitude_n
<< " feet and a Mach number of " << mach_n << endl << endl;
cout<< "The compressible dynamic pressure is "
<< subtraction << " pounds " << "per square inch.\n";
cout<< "The ambient pressure is "<< ambient << " pounds per square inch";
cin >> x;//screen open.
return 0;//returning
}
//-----------------p_ambient Function---
// ---------------
float p_ambient(float altitude) //p_ambient function.
{
float amb_temp; //ambient tempature
float amb_pres; //ambient pressure.
amb_temp = 518.688 - (3.56613e-03 * altitude);
amb_pres = 14.696 * pow( (amb_temp/518.688),5.2561);
return (amb_pres);//returning ambient pressure.
}
//-----------------p_ratio Function-----
// -------------
float p_ratio(float mach)//P_ratio function.
{
float eq; //to store the equation.
float power;//to store the power.
float answer;//to store the whole problem.
eq = ((pow(mach,2))*((GAMMA-1)/2))+1;
power= (GAMMA)/(GAMMA-1);
answer= pow(eq,power);
return (answer); //Returning the answer.
}
//-----------------End Program----------
// --------------