Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use a file to determine the lift angle and coefficient using a file called tunne

ID: 3581518 • Letter: U

Question

Use a file to determine the lift angle and coefficient using a file called tunnel.txt(on the right) to determine which in the file is a direct match or a value that falls in between them.

In this exercise you will read the fight data from tunnel.trt to two arrays lift anglell and lift coeffI] From the data loaded into the lift coe array you will search to see the minimum and maximum lift coefficient values and indexes they happen at. Then determine the associated lift angle from the lift angle array and set the minimum and maximum user input range. If the minimum or maximum input angles are exceeded a message will be displayed and the input process repeated Once a valid lift angle is input then search the lift angle[] array to determine if the value is a direct match then output a corresponding coefficient of lift. If the input angle is not a direct match then determine two points that the inputted angle falls between. Pass these two values to a function that performs linear interpolation and returns a lift coefficient that is interpolated Create the following user interface displaying either exact matches or interpolated results, also if the inputs are o of bounds. On the right is the data in tunnel.txt (note when reading the file you must detect either the EOF or the number of fields using the fscanf function to determine when to step reading 10 0.097 Enter lift angle between 0.05 putted Angle and Coefficient of -0.14 Enter lift angle between 0.182 puutted Angle 18 and Coefficient of -0.056 Enter lift angle between -4 and 18 degre Coefficient of lift -0.087 0.097 0.238 Enter lift angle between -4 and 18 degrees 5.5 Interpolated Angle between 4 & 6 and Coefficient of lift 0.464 0.421 0.479 Enter lift angle between 4 and 18 degrees -5 Lift angle out of range, cannot interpolate 0.654 Enter lift angle between 4 and 18 degrees 20 10 0.792 Lift angle out of range cannot interpolate 12 0.924 Enter lift angle between 4 and 18 degrees 14 1.035 15 1.076 16 1.103 17 1.12 18 1.121 19 1.121 20 1.099 21 1.059 22 1.013 23 1.01

Explanation / Answer

#include <iostream>
#include <string>
#include <fstream>

using namespace std;

const int T=100;
double maxval(const double x[], int n);
double minval(const double x[], int n);

int main()
{
  
    int tpts(0);
    double y[T], lift_angle,lift_coeff;
    string filename;
    ifstream tunnel;


    cout << "Enter the name of the data file";
    cin >> filename;
    tunnel.open(filename.c_str());
    if (tunnel.fail())
    {
        cout << "Error opeing input file ";
    }
    else
    {
      
        tunnel >> lift_angle >> lift_coeff;

      
        while (tpts <= T-1 && !tunnel.eof())
        {
            y[tpts] = lift_angle;
            tpts++;
            tunnel >> lift_angle;
        }

     
        cout << "Range of lift_angle angles: " << minval(y,tpts) << " to " << maxval(y,tpts) << " degrees"<< endl;
           
       

      
        tunnel.close();
    }
return 0;
}

double maxval(const double x[], int n)
{
  
    double max_x;


    max_x = x[0];
    for (int k=1; k<=n-1; k++)
    {
        if (x[k] > max_x)
            max_x = x[k];
    }

  
    return max_x;
}


double minval(const double x[], int n)
{

        double min_x;
  
        min_x = x[0];
        for (int k=1; k<=n-1; k++)
        {
            if (x[k] < min_x)
                min_x = x[k];
        }


        return min_x;
}