I have successfully opened and discarded the headers. Then I calculated the distances between point 1 and others and the minimum distance as well. However, I am not sure how to make the code work for more than 4 points. The text file I am trying to extract data from looks like:
Coordinates of many points (1st line)
x y z (second)
-0.06325 0.03597 0.042823 (third line)
. . . . . . . . .
continued .. and point 1 has coordinates (-0.06325, 0.03597 , 0.042823).
Also, I need to tell which is the closest point to point 1 and the distance between point 1 and the closest point on the output screen, could you help me? Thank you.
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
double x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, dist_12, dist_13,
dist_14, minimum_distance;
ifstream inFile("input-week6-ad-q4-2.txt"); // ifstream function to read the
file
string line, c; // To read the characters
char ch;
if (inFile.is_open())
{
getline(inFile, line); // To read the header of the input file then
discard it
getline(inFile, line);
inFile >> x1 >> y1 >> z1;
inFile >> x2 >> y2 >> z2;
inFile >> x3 >> y3 >> z3;
inFile >> x4 >> y4 >> z4;
int i = 1;
while (inFile >> xi >> yi >> zi) {
i++;
}
int number_of_points = i;
inFile.close();
}
else
cout << "The file could not be opened." << "\n"; // To check for any
error
system("pause");
return 0;
}