1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
int distance (float pointX1, float pointX2, float pointY1, float pointY2);
int slope (float pointX1, float pointX2, float pointY1, float pointY2);
int main()
{
float inputX1, inputX2, inputY1, inputY2, distanceOut, slopeOut;
cout << fixed;
cout << "Enter x1: ";
cin >> inputX1;
cout << "Enter y1: ";
cin >> inputY1;
cout << "Enter x2: ";
cin >> inputX2;
cout << "Enter y2: ";
cin >> inputY2;
distanceOut = distance(inputX1, inputX2, inputY1, inputY2);
slopeOut = slope(inputX1, inputX2, inputY1, inputY2);
cout << "The distance is " << setprecision(2) << distanceOut << endl;
if (inputY1 == inputY2)
{
cout << "The line is horizontal";
}
else if (inputX1 == inputX2)
{
cout << "The line vertical.";
}
else
{
cout << "The line is neither horizontal nor vertical.\n";
cout << "The slope is " << setprecision(2) << slopeOut << endl;
}
return 0;
system("pause");
}
int distance (float pointX1, float pointX2, float pointY1, float pointY2)
{
float distanceCalc;
distanceCalc = sqrt(pow((pointX2-pointX1),2) + pow((pointY2-pointY1),2));
return distanceCalc;
}
int slope (float pointX1, float pointX2, float pointY1, float pointY2)
{
float slopeCalc;
slopeCalc = ((pointY1-pointY2)/(pointX1-pointX2));
return slopeCalc;
}
|