Question: Given two points (x1, y1) and (x2, y2), the slope of the line running through those points is defined as rise / run, or (y2-y1)
Given two points (x1, y1) and (x2, y2), the slope of the line running through those points is defined as rise / run, or
(y2-y1) / (x2-x1)
For example, given the points (1, 3) and (4, 10), the slope is 2.33333. Write a complete C++ program to compute the slope of a line. The input to the program are 4 integer values in the order x1, y1, x2 and y2. For example, (1, 3) and (4, 10) are input as follows:
1 3 4 10
The program then computes the slope and outputs both the points, and the resulting slope. Given (1, 3) and (4, 10), here's the format of the output to produce:
(1,3) (4,10) Slope: 2.33333
There is one space following the ":", and each line is followed by a newline. Since the slope is a real number, you should work with variables of type double. Even though the inputs are integers, note that you can input these values into variables of type double without error. Assume for this exercise that the run will never be 0, thus avoiding division by 0.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
