Ok I have a program due on Monday. Just seeing if yall can help me out. I have tried different code but cant get the program to do everything its supposed to do.
Here's the assignment:
Wind-tunnels are test chambers built to generate precise wind speeds. Accurate scale models of new aircraft can be mounted on a force-measuring supports in the test chamber, and measurements of the forces on the model can be made at different wind speeds and angles. Some wind tunnels can operate at hypersonic velocities, generating wind speeds of thousands of miles per hour. The sizes of the wind-tunnel test chamber vary from a few inches across to sizes large enough to accommodate a jet fighter. At the completion of a wind-tunnel test series, many sets of data have been collected that can be used to determine lift, drag, and other aerodynamic performance characteristics of a new aircraft at its various operating speeds and positions.
The collected data points can be used to estimate the performance of the aircraft at speeds and positions that are within the range of the experimental measurements but not equal to the original data. This is called interpolation. There are various ways of doing interpolation, the easiest of which is probably linear interpolation. For example, suppose we have data points (a, f(a)) and (c, f(c)). If we want to estimate the value of f(b), where a < b < c, we could assume that a straight line joined f(a) and f(c) and then use linear interpolation to estimate the value of f(b). The formula to do this is [f(a)-f(b)]/[b-a] = [f(a)-f(c)]/[c-a]. A nice illustrated explanation of linear interpolation can be found on pages 52 and 53 of your textbook.
The input file tunnel.txt contains 17 wind-tunnel measurement pairs which consist of a flight-path angle (in degrees) and its corresponding coefficient of lift on each line in the file. The flight-path angles are in ascending order. Write a program that reads the wind-tunnel data into an appropriate array(s), prints a message showing the range of angles that are covered in the data file, and then allows the user to enter a flight-path angle. If the angle is within the bounds of the data set, the program should then use linear interpolation to compute the corresponding coefficient of lift and display it on the screen. If the userís input is outside the range, the program should print an error message indicating so. The program should keep asking the user to enter flight-path values as long as the user desires. A sample program run using the input file tunnel.txt is shown below.
Your program should be contained in a single source code file called lastname_prog6.cpp (where lastname is your last name) and must follow the code format guidelines for this class (click here for these guidelines).
Here is the sample run:
The following shows a sample program run using the input file tunnel.txt (user input in bold).
Range of flight-path angles: -4 to 21 degrees
Please enter a flight-path angle in degrees: -3
Lift coefficient for -3 degrees: -0.119
Would you like to enter another value (Y/N)? y
Please enter a flight-path angle in degrees: -5
****Sorry, -5 is not within data range****
Would you like to enter another value (Y/N)? Y
Please enter a flight-path angle in degrees: 5.5
Lift coefficient for 5.5 degrees: 0.59575
Would you like to enter another value (Y/N)? N
Here is the data file "tunnel.txt":
And here is my code:
I found out how to do the range, but nothing else. I know this is long but I can really use the help.
using namespace std;
//Define constants and declare function prototypes
const int T=100;
double maxval(const double x, int n);
double minval(const double x, int n);
// Declare objects
double y[T], flight_range, coef_lift;
// Prompt user for file name and open date file.
cout << "Enter the name of the data file";
cin >> filename;
cout << "Error opeing input file\n";
// Read a data value from the file
tunnel >> flight_range >> coef_lift;
// While there is room in the array and
// end of file was not encountered,
// assign the value to the array and
// input the next value.
while (tpts <= T-1 && !tunnel.eof())
y[tpts] = flight_range;
tunnel >> flight_range;
// Find and print the maximum value
cout << "Range of flight-path angles: " << minval(y,tpts) << " to " << maxval(y,tpts) << " degrees"<< endl;
// Close file and exit program
/* This function returns the maximum */
/* value in the array x with n elements */
double maxval(const double x, int n)
// Declare local objects
// Determine maximum value in the array
max_x = x;
for (int k=1; k<=n-1; k++)
if (x[k] > max_x)
max_x = x[k];
// Return maximum value
/* This function returns the minimum */
/* value in an array x with n elements */
double minval(const double x, int n)
// Declare objects
// Determine minimum value in the array
min_x = x;
for (int k=1; k<=n-1; k++)
if (x[k] < min_x)
min_x = x[k];
// Return minimum value