Slope Formula
Program
Overview:
In this program, you’ll let the user see the slope of a line when the
user supplies two points.
Background:
The slope of
a line is determined by dividing the rise by the run. (Rise over Run).
The rise is
found by subtracting the second y from the first y. (or y1 – y2).
The run is
found by subtracting the second x from the first x. (or x1 – x2).
Slope is
often referred to by the letter m in mathematics.
Specifics:
First, you
should have a title screen. Show
the name of the program (make up something), class information, and your
name. Use the SLEEP command to show this
on the screen for about 2 or 3 seconds.
Second, your
screen should clear and the program purpose/directions should follow. Explain what the program does and tell the
user what is expected of them. Use the
SLEEP command to pause for a few seconds while the user reads.
Third, the
user should have to enter information about the first point (x1 and y1).
Fourth, the
user should have to enter information about the second point (x2 and y2).
Next, the
program should compute the slope of the line.
Finally, the
program should report results to the user.
The two points should show as part of the report. (See sample below).
Sample I/O:
Enter the first
point:
X1? 4
Y1? 3
Enter the second
point:
X2? 6
Y2? 7
The slope of the
line between ( 4 , 3 ) and ( 6 , 4 ) would be 2.
Slope
Formula Program – Version 2
Overview:
When you have two spots, you can find the distance between them. This is true whether the spots are two points
on a grid (like the slope program) or two locations on the Earth, like Auburn
and Linwood.
Lots of
programs rely on finding the distance between two points. Think about the modern navigation systems
that are in new cars. These navigation
systems use programs that need to know where you are now (by GPS) and where you
are going to give you directions. On the
Earth, every location is determined by longitude and latitude, which is really
just a grid.
Another use
of this is in web sites that provide mapping, like MapQuest or Google
Maps. These sites run programs that
calculate distances.
You can
adjust your SLOPE program so that it calculates distance as well. The distance formula is a little trickier,
but still workable.
Calculating
Distances:
To find the distance
between two points, you must first find out how much space is between them
vertically and horizontally.
Examine the points
(-3,5) and (8, 2).
The first number in each pair shows how far “over” each point is. So, the first point is -3 units over and the
second point is 8 units over. The number
of units (horizontally) between these two is 11. The second number in each pair shows how far “up”
the point is. The first point is 5 units
up and the second point is only 2 units up.
The number of units (vertically) between these two is 3 units.
So, the two
points are 11 units apart horizontally and 3 units apart vertically. To find the distance between, you have to
square both numbers. 11 squared is 121
and 3 squared is 9.
Next, you
add the squares. 121 + 9 = 130.
Finally, you
take the square root of the result. The
square root of 130 is about 11.4. So,
the distance is 11.4 units.
Specifics:
Adjust your
slope program so that it calculates distance.
You’ll need to research how to do square roots. The distance formula can be written in an
expression as this:
Distance =
sqrt( (x1-x2)^2 + (y1–y2)^2)