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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <cmath>
#include <fstream>
#include <vector>
using namespace std;
bool calculateAccelerationArray(vector<double> t, vector<double>& p, vector<double> v, vector<double>& a);
void displayAcceleration(vector<double> t, vector<double> p, vector<double> v, vector<double> a);
vector<double> t, v, a, p, n;
double Number=0;
double Time, Velocity, Acceleration, Altitude;
int main(int argc, char *argv[])
{
const int Length_of_Line(50);
char quit, string1[Length_of_Line];
std::ifstream Rocket_Data_Input;
Rocket_Data_Input.open("rocketVelocityData.txt"); //This will open the input file.
Rocket_Data_Input.getline(string1,Length_of_Line);
if (Rocket_Data_Input.fail()) // Checks for proper opening of the report.
{
cerr << " Your Report failed to open. \n";
}
// cout << " Number " << " TIME " << " Velocity " << endl;
while (!Rocket_Data_Input.eof()) // Takes data from input file.
{
Rocket_Data_Input >> Time >> Velocity;
// cout << " " << left << setw(5) << Number << " " << left << setw(8) << Time
// << left << setprecision(12) << setw(16) << Velocity << endl;
t.push_back(Time);
v.push_back(Velocity);
}
calculateAccelerationArray(t, p, v, a);
displayAcceleration(t, p, v, a);
quit = '\0'; //slows down the logout to allow user time to see screen.
while (quit != 'q')
{ cout << "Press q to quit ";
cin >> quit;
}
return EXIT_SUCCESS;
}
bool calculateAccelerationArray(vector<double> t, vector<double>& p, vector<double> v, vector<double>& a)
{
//while (!calculateAccelerationArray(t, p, v, a)==false)
// {
//Pushing the first(zero) value to the acceleration vector and the position vector.
for (int j=0; j<t.size()-1; j++)
{//This is for the first instance when other method will not work.
if (j==0)
{
int next=j+1;
int prev=j-1;
Acceleration = (v.at(next)-v.at(j))/(t.at(next)- t.at(j));
Altitude = 0;
a.push_back(Acceleration);
// p.push_back(Altitude);
cout << Number << " " << Time << " " << Altitude << " " << Velocity << " " << Acceleration << endl;
break;
}
}
for (int i=0; i<t.size()-1; i++)
{//This is for the remaining data.
int next=i+1;
int prev=i-1;
//Pushing correct values into the remaining spots in the position and acceleration vector objects.
if (i>=1 && i<t.size()-1)
{
Altitude = ((p.at(prev))+((t.at(i)-t.at(prev))*(v.at(i)+v.at(prev)))/2);
p.push_back(Altitude);
Acceleration = (v.at(next)-v.at(prev))/(t.at(next)- t.at(prev));
a.push_back(Acceleration);
cout << Number << " " << Time << " " << Altitude << " " << Velocity << " " << Acceleration << endl;
break;
}
}
for (int i=0; i=t.size()-1; i++)
{//This is for the remaining data.
int next=i+1;
int prev=i-1;
//Pushing correct values into the remaining spots in the position and acceleration vector objects.
if (i=t.size()-1)
{
Altitude = ((p.at(prev))+((t.at(i)-t.at(prev))*(v.at(i)+v.at(prev)))/2);
p.push_back(Altitude);
Acceleration = (v.at(i)-v.at(prev))/(t.at(i)- t.at(prev));
a.push_back(Acceleration);
cout << Number << " " << Time << " " << Altitude << " " << Velocity << " " << Acceleration << endl;
break;
}
}
return true;
// }
}
void displayAcceleration(vector<double> t, vector<double> p, vector<double> v, vector<double> a)
{
cout << "Number Time(s) Altitude(m) Velocity(m/s) Acceleration(m/s"<<char(253)<<")"<<endl;
cout.setf(ios::fixed);
cout.precision(3);
for (int i=0; i<t.size()-1 ; i++)
{
cout<<setw(3)<<i<<setw(11)<<t[i]<<setw(11)<<p[i]<<setw(13)<<v[i]<<setw(16)<<a[i]<<endl;
}
}
|