How to use functions to read data from file?

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.


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
 

#include <iostream>
#include <cstdlib>
#include <iomanip>
using namespace 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?
Topic archived. No new replies allowed.