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

The distance between two points can be calculated using the following expression

ID: 3620869 • Letter: T

Question

The distance between two points can be calculated using the following expression:

Distance = root (X2-X1)^2 + (Y2-Y1)^2

In this expression X 1 and Y 1 represent the coordinates of one point and X 2 and Y 2 represent the coordinate of the other point.

An input file (called value . dat ) containing eight sets of paired points is provided as listed below. Write a program to calculate the distance between each set of paired points of this input file using the following restrictions:

The program should represent each point by a structure called point , having two members ( X and Y ).
The program should use a function to calculate the distance between each pair of points. The inputs to the function are two variables of type point and the output is the distance.
The program should read the coordinates of points from the input file and write the distance with the corresponding coordinates of the points to an output file similar to the one shown(with proper heading).
You must create your input file using the values provided.
Input file( Value . dat ) Output file
X1 Y 1 X 2 Y 2 Distance
0.0 0.0 2.0 1.8 0.0 0.0 2.0 1.8 .......
1.0 -3.0 2.8 3.5 1.0 -3.0 2.8 3.5 .......
2.2 4.4 1.1 6.8 2.2 4.4 1.1 6.8 .......
-8.0 -6.0 7.0 7.2 -8.0 -6.0 7.0 7.2 .......
5.4 2.4 -9.0 -4.6 5.4 2.4 -9.0 -4.6 .......
3.0 4.0 2.0 3.0 3.0 4.0 2.0 3.0 .......
2.3 3.4 4.4 5.5 2.3 3.4 4.4 5.5 .......
7.3 7.3 9.3 9.3 7.3 7.3 9.3 9.3 .......

Explanation / Answer

please rate - thanks #include <iostream>
#include <fstream>
#include<cmath>
#define points 8
using namespace std;

struct point
{double x;
double y;
};
double dist( point, point);        
int main()
{point a,b;
int i;
double d;
ifstream in;
ofstream out;
in.open("value.dat");
if(in.fail())          
       { cout<<"input file did not open please check it ";
        system("pause");
        return 1;
        }
out.open("output.dat");          
out<<"X1 Y1 X2 Y2 Distance ";
for(i=0;i<points;i++)
     {in>>a.x>>a.y>>b.x>>b.y;
     d=dist(a,b);
     out<<a.x<<" "<<a.y<<" "<<b.x<<" "<<b.y<<" "<<d<<endl;
     }
in.close();
out.close();
}
double dist(point a, point b)
{double d;
d=sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
return d;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote