Write a program with modular structure that asks the user for two points on a line, calculates the slope of the line, and determines whether the line is horizontal, vertical, falling from left to right, or rising left to right. My program should consist of two functions: one for calculating slope (in which I already have created) and another that determines the line direction.
I have created the function for calculating the slope of the line, however, I am not sure as to how I should go about creating a function that will determine the direction of the line itself. Also, I must check if the slope is undefined. (Knowing that if the denominator = 0, the slope will be undefined)
Make slope double value. That way vertical lines (when slope denominator is 0) will be represented by infinity special value you can check with isinf() function: http://en.cppreference.com/w/cpp/numeric/math/isinf
example:
1 2 3
double s = 1/0.0;
if(std::isinf(s))
std::cout << "vertical";
vertical
To detemine direction you should check slope: if it is 0, line is horisontal, if it is positive, line is rising, negative — falling.