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
|
double inf = std::numeric_limits<double>::infinity();
using namespace std;
int distance ();
int slope ();
int main ()
{
float x1i, y1i, x2i, y2i;
string clause;
cout << setprecision(3);
cout << "Enter x1: ";
cin >> x1i;
cout << "Enter y1: ";
cin >> y1i;
cout << "Enter x2: ";
cin >> x2i;
cout << "Enter y2: ";
cin >> y2i;
float distance = distance (x1i,y1i,x2i,y2i);
cout << "The distance is " << distance << ".";
float slope = slope (x1i,y1i,x2i,y2i);
if (slope == 0) {
clause = "\nThe line is horizontal.";
cout << clause << endl;
}
else if (slope == inf) {
clause = "\nThe line is vertical.";
cout << clause << endl;
}
else { (slope <0 || slope > 0) ;
clause = "neither vertical nor horizontal.";
cout << "\nThe slope is " << slope << ", " << clause << endl;
}
}
double distance (x1,y1,x2,y2) {
distance = sqrt(pow((x2-x1) ,2) + pow((y2 - y1) ,2));
cout << "The distance is " << distance << ".";
return distance;
}
double slope (x1,y1,x2,y2) {
slope = ((y1-y2)/(x1-x2));
return slope;
}
| |