daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jan 17th, 2018 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <cstdlib>
  5. #include <cmath>
  6.  
  7. using namespace std;
  8.  
  9. void readData (string fileName, vector<double> & flightPath, vector<double> & coLift);
  10. double interpolation (double flightAngle, const vector<double> & flightPath, const vector<double> & coLift);
  11. bool isOrdered (const vector<double> & flightPath);
  12. void reorder (vector<double> & flightPath, vector<double> & coLift);
  13.  
  14. int main() {
  15.     string fileName;
  16.     double flightAngle;
  17.     vector<double> flightPath;
  18.     vector<double> coLift;
  19.     string userResponse = "no";
  20.    
  21.  
  22.         cout << "Enter name of input data file:" << endl;
  23.         cin >> fileName;
  24.        
  25.         cout << endl;
  26.    
  27.         readData (fileName, flightPath, coLift);
  28.    
  29.         if (!isOrdered (flightPath)) {
  30.             reorder(flightPath, coLift);
  31.         }
  32.         // ==> Checks if vector is in order, if not it reorders it.
  33.    
  34.         cout << "Please enter a flight-path angle:" << endl;
  35.         cin >> flightAngle;
  36.    
  37.         cout << interpolation (flightAngle, flightPath, coLift) << endl;
  38.    
  39.         cout << "Would you like to enter another flight-path angle? (yes/no)" << endl;
  40.         cin >> userResponse;
  41.    
  42.     while (userResponse == "yes") {
  43.         cout << "Please enter a flight-path angle:" << endl;
  44.         cin >> flightAngle;
  45.    
  46.    
  47.         cout << interpolation (flightAngle, flightPath, coLift) << endl;
  48.    
  49.         cout << "Would you like to enter another flight-path angle? (yes/no)" << endl;
  50.         cin >> userResponse;
  51.     }
  52.    
  53.     return 0;
  54. }
  55.  
  56.  
  57.  
  58.  
  59. void readData (string fileName, vector<double> & flightPath, vector<double> & coLift) {
  60.     ifstream inSS;
  61.     double angle = 0.0;
  62.     double lift = 0.0;
  63.     inSS.open(fileName.c_str());
  64.    
  65.     if (!inSS) {
  66.         cout << "Error opening " << fileName << endl;
  67.         exit(1);
  68.     }
  69.    
  70.     while (inSS >> angle >> lift) {
  71.         flightPath.push_back(angle);
  72.         coLift.push_back(lift);
  73.     }
  74.    
  75. }
  76.  
  77. double interpolation (double flightAngle, const vector<double> & flightPath, const vector<double> & coLift) {
  78.    int j;
  79.    double answer;
  80.    int size = static_cast<int> (flightPath.size());
  81.    
  82.    
  83.     for (j = 0; j + 1 < size; ++j) {
  84.         if (flightPath.at(j) > flightAngle) {
  85.             break;
  86.         }
  87.     }
  88.  
  89.     answer = coLift.at(j - 1) + ((flightAngle - flightPath.at(j - 1))) / (flightPath.at(j)
  90.     - flightPath.at(j - 1)) * (coLift.at(j) - coLift.at(j - 1));
  91.    
  92.     return answer;
  93.    
  94. }
  95.  
  96. bool isOrdered (const vector<double> & flightPath) {
  97.     int i;
  98.     int size = static_cast<int> (flightPath.size());
  99.    
  100.     for (i = 1; i < size; ++i) {
  101.         if (flightPath.at(i - 1) > flightPath.at(i)) {
  102.             return false;
  103.         }
  104.     }
  105.    
  106.     return true;
  107. }
  108.  
  109. void reorder (vector<double> & flightPath, vector<double> & coLift) {
  110.     int i;
  111.     int j;
  112.     int size = static_cast<int> (flightPath.size());
  113.    
  114.     for (i = 0; i < size; ++i) {
  115.         for (j = 1; j < size; ++j) {
  116.             if (flightPath.at(j - 1) > flightPath.at(j)) {
  117.                 swap (flightPath.at(j - 1), flightPath.at(j));
  118.                 swap (coLift.at(j - 1), coLift.at(j));
  119.             }
  120.         }
  121.     }
  122.    
  123.     return;
  124. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top