May 28, 2015 at 11:44pm UTC
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
void getPoint (double&, double&, double&, double &);
void calcDistance (double, double, double, double);
void findMidpoint (double, double, double, double, double&, double&);
bool findSlope (double, double, double, double, double&);
void outputResults (double, double, double, double, double, double, double);
int main()
{
double x1, y1, x2, y2, distance, midpointX, midpointY, slope, midpoint;
getPoint(x1, y1, x2, y2);
calcDistance(x1, y1, x2, y2);
findMidpoint (x1, y1, x2, y2, midpointX, midpointY);
findSlope (x1, y1, x2, y2, slope);
outputResults (x1, y1, x2, y2, distance, midpoint, slope);
return 0;
}
void getPoint(double& x1, double& y1, double& x2, double & y2)
{
cout << "Enter x1: ";
cin >> x1;
cout << "Enter y1: ";
cin >> y1;
cout << "Enter x2: ";
cin >> x2;
cout << "Enter y2: ";
cin >> y2;
}
void calcDistance (double x1, double y1, double x2, double y2)
{
double distance;
distance = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
distance = sqrt(distance);
cout << "Distance is: " << distance << endl;
}
void findMidpoint (double x1, double y1, double x2, double y2, double midpointX, double midpointY)
{
midpointX = (x1 + x2) / 2;
midpointY = (y1 + y2) / 2;
cout << "Midpoint: (" << midpointX << "," << midpointY << ")/n";
}
bool findSlope (double x1, double y1, double x2, double y2, double& slope)
{
bool undefined = false;
if (x2 - x1 == 0) undefined = true;
else slope = (y2 - y1) / (x2 - x1);
if (undefined == false)
cout << "Slope is: " << slope << endl;
else cout << "Slope is: " << "undefined" << endl;
}
void outputResults (double x1, double y1, double x2, double y2, double distance, double midpoint, double slope)
{
cout << "Points: " << "(" << x1 << "," << y1 << ")" << "(" << x2 << "," << y2 << ")" << endl;
cout << "Distance: " << distance << endl;
cout << "Midpoint; " << midpoint << endl;
cout << "Slope: " << slope << endl;
}