Source code

#include //This program is used to determine the
#include //amount of drag on three basic geometric
const float pi = 3.14159265359; //shapes at varying altitudes and speeds.
int main() //This program is written in Imperial measurement
{
double MASS, VELOCITY, SHAPE, surfacearea, oswoldfactor, ALTITUDE;
double airdensity, span, RADIUS, HEIGHT, WIDTH, CONELENGTH, aspectratio;
double CoLift, CoInducedDrag, CoParasiteDrag, CoDrag, TotalDrag, LENGTH;
//pressure drag, skin friction coefficient, Parasite drag, and induced drag were deemed obsolete and removed
int choice; //used for choosing shape
int num, max, prealt; //used for 'for' statement
cout << "Enter object type ((1)box (2)cylinder (3)cone): ";
cin >> choice;
if(choice == 1)
{
cout << "Enter the object's height in feet: ";
cin >> HEIGHT;
cout << "enter the object's width in feet: "; //Surface Area is in square feet
cin >> WIDTH;
surfacearea=HEIGHT*WIDTH;
oswoldfactor = .41; //<= usually determined through wind tunnel experimentation
span = WIDTH;
}
if(choice == 2)
{
cout << "Enter the radius in feet: ";
cin >> RADIUS;
surfacearea = pi * (RADIUS*RADIUS);
span = RADIUS * 2;
oswoldfactor = .67; //<= usually determined through wind tunnel experimentation
}
if(choice == 3)
{
cout << "Enter the radius in feet: " ;
cin >> RADIUS;
cout << "Enter the length from the tip to the bottom of the cone in feet: ";
cin >> LENGTH;
surfacearea = pi * RADIUS * LENGTH;
span = RADIUS * 2;
oswoldfactor = .89; //<= usually determined through wind tunnel experimentation
}
cout << "Enter the object's mass in slug(1 slug = 14.5943 Kg): ";
cin >> MASS;
cout << "Enter the object's velocity in ft/s: ";
cin >> VELOCITY;
cout << "Enter the number of altitudes being tested (21 total): ";
cin >> max;
for(num = 0; num < max; num++)
{
cout << "Enter the object's altitude in thousands of feet: ";
cin >> prealt;
ALTITUDE = 1000 * prealt;
if(ALTITUDE < 0)
{
cout << "Invalid altitude" << endl;
break;
}
if(ALTITUDE < 1000) // This program only gives approximate densities
airdensity = .002378;
else if(ALTITUDE < 2000)
airdensity = .002309;
else if(ALTITUDE < 3000)
airdensity = .002242;
else if(ALTITUDE < 4000)
airdensity = .002176;
else if(ALTITUDE < 5000) //Density is in slug/ft^3
airdensity = .002112; //(1 slug/ft^3 = 515.38 Kg/m^3)
else if(ALTITUDE < 6000)
airdensity = .002049;
else if(ALTITUDE < 7000)
airdensity = .001988;
else if(ALTITUDE < 8000)
airdensity = .001928;
else if(ALTITUDE < 9000)
airdensity = .001869;
else if(ALTITUDE < 10000)
airdensity = .001812;
else if(ALTITUDE < 11000)
airdensity = .001756;
else if(ALTITUDE < 12000)
airdensity = .001701;
else if(ALTITUDE < 13000)
airdensity = .001648;
else if(ALTITUDE < 14000)
airdensity = .001596;
else if(ALTITUDE < 15000)
airdensity = .001545;
else if(ALTITUDE < 16000)
airdensity = .001496;
else if(ALTITUDE < 17000)
airdensity = .001448;
else if(ALTITUDE < 18000)
airdensity = .001401;
else if(ALTITUDE < 19000)
airdensity = .001355;
else if(ALTITUDE < 20000)
airdensity = .001310;
else if(ALTITUDE >= 20000)
airdensity = 0.001267;

aspectratio = (span * span)/surfacearea;
CoLift= (2 * MASS)/ (surfacearea * airdensity * (VELOCITY * VELOCITY));
CoInducedDrag = (CoLift * CoLift)/(pi * oswoldfactor * aspectratio);
CoParasiteDrag = 0/(pi * oswoldfactor * aspectratio);
CoDrag = CoInducedDrag + CoParasiteDrag;
TotalDrag = CoDrag * surfacearea * .5 * airdensity * (VELOCITY * VELOCITY);
cout << "The total drag is " << TotalDrag << " pounds." << endl;
/*cout << "Coefficient: " << CoDrag << endl;
cout << CoParasiteDrag<< endl;
cout << CoInducedDrag<< endl;
cout << CoLift<< endl;
cout << surfacearea<< endl;
cout << airdensity<< endl;
cout << aspectratio<< endl; //used for verifying drag */
} //(checked against a source)
return 0;
}
Go back to home page.