Question: Coordinates Task : Input the coordinates of two points in the Cartesian coordinate system. Calculate the distance between the points and the midpoint between them.

Coordinates

Task: Input the coordinates of two points in the Cartesian coordinate system. Calculate the distance between the points and the midpoint between them. The program will be submitted in Java and also in C++. Also, include an appropriate algorithm.

Input: Accept 4 real numbers from the user, representing coordinates x1, y1, x2 and y2.

Processing:

Note that the C++ cmath library includes two useful functions, pow and sqrt.

Formulas:

distance: d2 = (x2-x1)2 + (y2-y1)2

midpoint: (x1+x2/2, y1 + y2/2)

Output: Print appropriate labels, the original points, the distance, and the midpoint. Print the original points and the midpoint with one decimal position; print the distance with two decimal positions.

Sample output (you may change the layout):

Points: (3.0, 2.5) (-1.0, 4.0)

Distance: 4.27

Midpoint: (1.0, 3.3)

Note: Please write a program both in Java and C++ with appropriate alogrithm that matches the programs.

Thank you,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!