| CS150 | Labs | Projects | Assignments | CodeSamples | Help Resources | Style Guide |
A point in a plain can be represented by giving it's x and y coordinates. A line segment can be represented by giving the two end points. A common task is to find the midpoint of a line segment given the two end points. The midpoint formula is given below:
Given two points (x1, y1) and (x2, y2) - the midpoint formula is:
xm = x2 + ((x1 - x2) / 2) and ym = y2 + ((y1
- y2) / 2)
Design, implement and test a C++ program that reads in two points (x and y coordinates) and calculates the midpoint
of the line segment.
Sample program run:
Welcome to the midpoint calculator program!!
Enter coordinates for point 1 (x coordinate first): 3 3
Enter coordinates for point 2 (x coordinate first): -1 1
//output
With point 1 equal to (3,3) and point 2 equal to (-1,1) The midpoint is (1,2). Thanks for using the midpoint calculator