Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help---Write a C++ programm for following problem: - The distance between

ID: 3786989 • Letter: P

Question

Please help---Write a C++ programm for following problem: - The distance between two points in 3-space is given by the formula:

The attached file (Points-3d) has six integers per line representing the three coordinates each of a pair of points in 3-space.
Write a program to determine how many pairs of points are greater than 10 units apart. Display the result as:
points read:___
points with distance greater than 10.0: ___

Use the following guidelines.
-represent each point by an array of three integer coordinates
-calculate the distance with a function that takes three parameters: two points, and the number of coordinates for a point
-read a pair of points with a function whose signature is bool readPoints(std::ifstream& ifs, int p1[], int p2[], int sz)
-return false on end-of-file, true otherwise

I don't know how to upload the text file here, so I copied and pasted it below. Thank you so much for helping.

2 5 2 8 5 2
9 0 0 1 3 0
0 8 8 9 6 3
3 9 1 8 5 2
1 4 10 0 0 9
9 8 1 3 6 8
9 10 7 3 2 5
4 8 1 4 10 6
0 0 5 8 5 9
4 1 3 9 1 9
8 5 1 10 5 8
4 1 10 3 2 0
2 0 2 4 6 10
10 7 10 10 2 8
4 10 8 1 3 8
5 5 7 6 6 2
4 3 7 4 2 6
1 8 9 5 4 7
5 4 0 5 4 0
1 8 6 2 10 7
1 1 8 4 5 5
3 5 1 2 0 5
4 7 3 9 0 3
7 3 2 0 0 7
7 5 6 4 9 7
3 4 3 3 9 2
7 1 0 3 0 2
9 8 2 4 10 4
1 10 1 6 0 5
3 5 9 3 4 1
9 5 7 9 4 6
1 1 3 4 7 8
0 3 7 8 10 7
0 8 5 10 7 8
4 1 7 7 7 3
5 3 1 4 4 10
7 7 0 10 3 9
4 5 6 5 2 2
10 8 4 1 9 0
10 0 6 10 2 3
2 10 8 8 4 4
7 1 5 2 1 10
0 6 1 9 0 0
3 7 10 0 5 3
2 0 6 6 6 10
7 5 6 5 8 9
8 2 1 9 1 3
7 5 10 3 0 10
5 6 1 1 3 5
1 0 0 0 9 1
3 7 6 8 9 9
6 9 2 1 6 8
5 2 10 5 1 8
0 9 0 8 7 8
5 10 10 0 9 1
4 9 4 7 0 4
8 8 0 10 3 8
8 9 7 5 6 0
1 9 3 10 7 4
9 7 4 5 1 5
9 7 0 9 8 1
6 3 9 0 1 3
7 4 3 7 9 4
1 4 7 6 8 6
9 4 1 3 3 6
6 3 8 6 3 0
0 8 10 3 9 7
3 9 10 0 2 6
2 2 3 4 4 9
8 9 9 4 3 4
9 9 4 10 0 6
1 3 3 10 5 7
10 7 9 5 0 9
6 3 5 7 5 3
0 7 10 10 9 3
8 2 1 9 6 8
2 7 1 1 8 1

Explanation / Answer

#include <iostream>
#include <cmath>
#include <fstream>
#include <sstream>
#include <string>
using namespace std;

bool readPoints(std::ifstream& ifs, int p1[], int p2[], int sz)
{
string line;
if (ifs.peek()!=EOF)
{
getline(ifs, line);
istringstream iss(line);
for(int i = 0; i <sz; i++)
{
iss >> p1[i];
}
for(int i = 0; i <sz; i++)
{
iss >> p2[i];
}
}

return (ifs.peek()!=EOF);
}

double distance(int p1[], int p2[], int sz)
{
double sum = 0;

for(int i = 0; i < sz; i++)
{
sum += (p1[i]-p2[i])*(p1[i]-p2[i]);
}

return sqrt(sum);
}

int main()
{
ifstream myfile ("Points-3d.txt");

int p1[3];
int p2[3];
int sz = 3;

cout << "Point read: " << endl;
while(readPoints(myfile, p1, p2, sz))
{
for(int i = 0; i < sz; i++)
{
cout << p1[i] << " ";
}
for(int i = 0; i < sz; i++)
{
cout << p2[i] << " ";
}
cout << endl;
}
myfile.close();

ifstream myfile1("Points-3d.txt");

cout << "points with distance greater than 10.0:" << endl;
while(readPoints(myfile1, p1, p2, sz))
{
double dist = distance(p1, p2, sz);

if (dist > 10.0)
{
for(int i = 0; i < sz; i++)
{
cout << p1[i] << " ";
}
for(int i = 0; i < sz; i++)
{
cout << p2[i] << " ";
}
cout << endl;
}
}
myfile1.close();
return 0;
}