Calculationg the lift coefficient full program assignment be
Calculationg the lift coefficient
full program assignment below. this chapter has to do with streams. I can\'t figure this one out. It is a zybooks assignment and my class uses cin/cout not printf and we dont type std: before lines of code.
prototypes that must be used for these functions:
Data File Format
The data file will have on each line, one flight-path angle (in degrees), a space, and then the corresponding coefficient of lift. See the following file examples, tunnel1.dat and tunnel2.dat. You must create these 2 files and turn them in with your program. Use these files to help you test your program, but do not assume these will be the only files we will test your program with. In other words, when testing your program you should also make up your own data files. You should try to come up with data files that will break your program if it doesn\'t follow all of the given specifications. That\'s what we will be doing when grading it.
tunnel1.dat
tunnel2.dat
PROGRAM Steps 1. Ask the user for the name of file that contains the wind tunnel data. 2. Read wind tunnel data into two parallel vectors, one vector stores the flight-path angle and the other stores the corresponding coefficient of lft for that angle. Both vectors should store doubles. 3. Ask the user for a flight-path angle. If the angle is within the bounds of the data set, the program should then use linear interpolation (see explanation of linear interpolation below) to compute the corresponding coefficient of lft and output it. 4. Finally, ask the user if they want to enter another fight-path angle. Repeat steps 3 and 4 if they answer yes, otherwise end the program if they answer no. For linear interpolation to work, the flight-path angles in the data fle must be in ascending order Ifthe fight-path angles are not in ascending order, your program will need to sort them before implementing Step 3 Linear Interpolation The wind-tunnel test data consists of some number of tested fight-path angles and their corresponding coefficient of lift. Using this data, we can estimate, using linear interpolation, the coefficient of lit for a fight-path angle within the bounds of the data set, even if that particular fight-path angle was not tested. If we want to find the coefficient of lift for fight-path angle b, we find flight-path angles a and c such that a b c Obviously, if flight path b already exists in the given data set, then you do not need to use linear interpolation. However, if it doesn\'t exist, then linear interpolation assumes a straight line exists between f(a and f(c) (In this case, f(a) is the coefficient of lift for flight-path angle a and f(c) is the coefficient of lift for flight-path angle c.)To find f(b), use the formula: f(b) f(a) f(c) f(a) (b a)/(c a) Modular Programming You must implement and useat least the following functions: read Data: passes in the name of a file and two vectors (double) and stores in the first vector the fight-path angles (first column) and in the second vector the corresponding coefficients of lift (2nd column). If the file does not open properly, this function should output an error message and then call the exit function passing it an exit value of 1 interpolation: passes in the requested flight-path angle along with the 2 vectors of data (fight path angles and corresponding coefficients of lit) and returns the corresponding coefficient of lift. isordered: passes in the vector of flight-path angles and returns true ifitstores the angles are in ascending order, otherwise returns false. reorder passes in both vectors of data and then reorders the data so that the flight path angles are in ascending order while maintaining the correspondence between the flight-path angles and their corresponding coefficients of lift.Solution
//C++ code
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <cmath>
using namespace std;
void readData(const string &inputFile, vector<double> &one, vector<double> &two)
{
ifstream inFile;
double a = 0.0 , coff=0.0;
inFile.open(inputFile.c_str());
if(!inFile)
{
cout << \"File now found\ \";
exit(1);
}
while(inFile >> a >> coff)
{
one.push_back(a);
two.push_back(coff);
}
}
double interpolation(double input_User, const vector<double> &one, const vector<double> &two)
{
int up = 0, down = 0;
double coff = 0.0, t1, t2, t3, t4, t5;
for(int i = 0; i < one.size(); i++)
{
if(input_User == one.at(i))
{
return two.at(i);
}
}
for(int j = one.size() - 1; j >= 0; j--)
{
if((one.at(j) - input_User) < 0)
{
down = j;
break;
}
}
for(int i = 0; i < one.size(); i++)
{
if((one.at(i) - input_User) > 0)
{
up = i;
break;
}
}
t1 = two.at(down);
t2 = two.at(up);
t3 = one.at(down);
t4 = input_User;
t5 = one.at(up);
coff = t2 + (t4 - t3)/(t5 - t3)*(t1 - t2);
return coff;
}
bool isOrdered(const vector<double> &one)
{
for(int i = 1; i < one.size(); i++)
{
if(one.at(i) < one.at(i - 1))
{
return false;
}
}
return true;
}
void reorder(vector<double> &one, vector<double> &two)
{
for(int i = 0; i < one.size(); i++)
{
for(int i = 1; i < one.size(); i++)
{
if(one.at(i) <one.at(i - 1))
{
swap(one.at(i - 1), one.at(i));
swap(two.at(i - 1), two.at(i));
}
}
}
return;
}
int main()
{
double input_User = 0;
string inputFile, next = \"y\";
vector<double> one;
vector<double> two;
cout << \"Enter filename:\";
cin >> inputFile;
readData(inputFile, one, two);
// check ordered or not
if(!isOrdered(one))
{
// reorder if not in order
reorder(one, two);
}
while(next != \"n\")
{
cout << \"Enter angle: \";
cin >> input_User;
cout << \"coefficient: \" << interpolation(input_User, one, two) << endl;
cout << \"Do you want to enter angle again(y/n): \";
cin >> next;
}
return 0;
}
/*
tunnel1.dat
-4.0 -0.182
-2.0 -0.056
0.0 0.097
2.0 0.238
4.0 0.421
6.0 0.479
8.0 0.654
10.0 0.792
12.0 0.924
14.0 1.035
15.0 1.076
16.0 1.103
17.0 1.120
18.0 1.121
19.0 1.121
20.0 1.099
21.0 1.059
output:
Enter filename: tunnel1.dat
Enter angle: 45
coefficient: -1.37336
Do you want to enter angle again(y/n): y
Enter angle: 33
coefficient: -0.77768
Do you want to enter angle again(y/n): y
Enter angle: 2
coefficient: 0.238
Do you want to enter angle again(y/n): n
*/



