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
|
#include <iostream>
#include <fstream>
using namespace std;
int ordered(double fp_angle[], int num_pts);
void reorder(int count_pts,double &x, double &y);
int main(void)
{
int i,num_pts;
double fp_angle[num_pts], lift[num_pts],order,interp;
string filename;
ifstream infile;
cout << "Enter the name of the input file." << endl;
cin >> filename;
cout << endl;
infile.open(filename.c_str());
if(!infile)
{
cout << "File could not be opened.\n";
return 0;
}
i=0;
cout<<"Enter the number of points in the file: ";
cin>>num_pts;
while (infile>>fp_angle[i]>>lift[i])
{
i++;
order=ordered(fp_angle,num_pts);
cout<<"Checking to see if file is in order...";
if (order==0)
{
cout<<"This file is not ascending order";
reorder(num_pts, fp_angle[i], lift[i]);
}
else
{
cout<<"Enter a flight path angle: ";
cin>>fp_angle[i];
interp=lift[i-1]+((fp_angle[i]-fp_angle[i-1])*(lift[i+1]-lift[i-1])/(fp_angle[i+1]-fp_angle[i-1]));
}
}
system("pause");
return 0;
}
int ordered(double fp_angle[], int num_pts)
{
for(int k=0;k<=num_pts;k++)
{
if(fp_angle[k]<fp_angle[k+1])
return 1;
if(fp_angle[k]>fp_angle[k+1])
return 0;
}
}
void reorder(int count_pts,double &x, double &y)
{
int j,m,k,swap;
for (k=0; k<=count_pts-2; k++)
{
m=k;
for(j=k+1; j<=count_pts-1;j++)
{
if (x[j]<x[m])
m=j;
}
swap=x[m];
x[m]=x[k];
x[k]=swap;
}
}
|