// This program will get the coordinates of 3 points
// in the x-y plane and calculate the distance between
// each pair of points
#include <iostream>
#include <cmath>
using namespace std;
float get_x (); // get an x from the user
float get_y(); // get a y from the user
float distance (float x1, float y1, float x2, float y2);
// calculate the distance between x1, y1 and x2, y2
void showdist (float x1, float y1, float x2, float y2, float dist);
// display the distance between x1, y1 and x2, y2
int main ()
{
float x1, y1, x2, y2, x3, y3;
float dist1, dist2, dist3;
x1 = get_x();
y1 = get_y();
x2 = get_x();
y2 = get_y();
x3 = get_x();
y3 = get_y();
dist1 = distance (x1, y1, x2, y2);
dist2 = distance (x1, y1, x3, y3);
dist3 = distance (x2, y2, x3, y3);
showdist (x1, y1, x2, y2, dist1);
showdist (x1, y1, x3, y3, dist2);
showdist (x2, y2, x3, y3, dist3);
return 0;
}
/* get_x will prompt the user for an x part of a point's coordinate
read it from the keyboard and return it
*/
float get_x()
{ float x;
cout << "Enter the x coordinate ";
cin >> x;
return x;
}
/* get_y will prompt the user for a y part of a point's coordinate
read it from the keyboard and return it
*/
float get_y()
{
float y;
cout << "Enter the y coordinate ";
cin >> y;
return y;
}
/* distance will calculate (using the distance formula)
the distance from point x1, y1 to point x2, y2
and return it
*/
float distance (float x1, float y1, float x2, float y2)
{
return sqrt (pow(x1 - x2, 2) + pow (y1-y2,2));
}
/* showdist will output to the screen the sentence
"The distance between point x1, y1 and point x2, y2 is dist"
and then a carriage return
*/
void showdist (float x1, float y1, float x2, float y2, float dist)
{
cout << "The distance between ("<< x1<<", " << y1
<< ") and ("<< x2 << ", " << y2 << ") is " << dist
<< endl;
}