Hello, I need help with getting a set of values from a .txt file into a C++ code, where I am supposed to categorize them into x axis values and y axis values, then use the trapezoidal rule to get the area under that set of values. Getting the values into the C++ code was completed, however, I do not know how many values will be in the .txt file. Is there a way to limit it to the number of values in the .txt file? The text file and the code I made are shown below. We have been instructed to use structures, so that is what I used here.
The text file is named "curve_s1.txt", with the following values:
1.0 4.5
3.0 10.0
5.0 8.5
6.0 6.0
7.0 7.3
8.0 8.2
9.0 10.5
11.0 13.5
Have you read about std::vector? It is dynamic. It can grow as needed.
You have exactly one struct object in your program.
You read 20 values to its first member array (the xAxis).
You read 400 values to its second member array (the yAxis).
How about a struct that contains only one data point?
Create a list (std::vector) of points.