The purpose of the program below is to read in a list of thrust curve points which are stored in a two dimensional array. Then using the points the thrust for any given time is calculated.
#include <iostream>
#include <cstdlib>
#include <iomanip>
usingnamespace std;
// Main Program
int main( )
{
double timethrust[50][2]; // multidimensional array to store thrust data
double thrustattime, // thrust for the given time
wantedtime, // time for which thrust is calculated
point1, // first point of segment
point2, // second point of segment
thrustpoint1, // thrust of first point
thrustpoint2; // thrust of second point
char answer; // user enters Y or y to run program again
point1=0; // initializes first point to 0
thrustpoint1=0; // initializes thrust of first point to 0
point2=0; // initializes second point to 0
thrustpoint2=0; // initializes thrust of second point to zero
// Output Identification
system("CLS");
cout << "Take Home #11 - "
<< "Compute Engine Thrust Using Arrays\n\n";
do
{
// ask user for the thrust data and reads it into array
cout << "Enter thrust curve data (0 for thrust to end list):\n";
for(int i=0; i<10; i++) // for loop to enter points
{
// for loop to enter thrust of points
for(int t=0; t<2; t++)
{
// enters time and thrust into array
cin >> timethrust[i][t];
// if user enters 0 list ends
if(timethrust[i][t] == 0)
break;
}
}
// ask user for time in seconds
cout << "Enter a time: ";
cin >> wantedtime;
if(wantedtime>0)
{
for(int i=1; i<50; i++)
{
if(timethrust[i][0] > wantedtime)
{
point1 = timethrust[i-1][0];
thrustpoint1 = timethrust[i-1][1];
point2 = timethrust[i][0];
thrustpoint2 = timethrust[i][1];
break;
}
}
}
// calculates thrust for wanted time if time is between segment
if(point1 < wantedtime && point2 > wantedtime)
{
// calculates thrust for any given time
thrustattime = ((wantedtime - point1) / (point2 - point1)) *
(thrustpoint2 - thrustpoint1) + thrustpoint1;
// sets thrust = 0 if calculated thrust = 0
if(thrustattime < 0)
{
thrustattime = 0; //
}
}
// if time entered is not in segment then sets calculated thrust = 0
else
{
thrustattime = 0;
}
// outputs the engine thrust for time of interest
cout << "The thrust at time " << wantedtime << " is " << thrustattime << " newtons.\n";
// ask user if program should run again
cout << "Would you like to run the program again? ";
cin >> answer;
}while(answer == 'Y' || answer == 'y');
return 0;
}
But now I have to update the program and include two functions. The first function will read the thrust curve points from a text file after the user enters the name of the file.
int getthrustData(char filename[], double thrustCurve[][2]);
After that the user enters the time for which they want thrust calculated. So the second function calculates the thrust for the entered time and returns a value double.
double thrust(double time, const double thrustcurve[][2]);
I'm confused on how to include the functions? Any ideas?