Task: Input the coordinates of two points in the Cartesian coordinate system. Ca
ID: 3884312 • Letter: T
Question
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 x_1, y_1, x_2 and y_2. Processing: Note that the C++ cmath library includes two useful functions, pow and squareroot Formulas: Processing: distance d = squareroot (x_2 - x_1)^2 + (y_2 - y_1)^2 midpoint: (x_1 + x_2/2, y_1 + y_2/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)Explanation / Answer
c++ program
#include <iostream>
#include <cmath>
using namespace std;
double calcDistance (double x1, double y1, double x2, double y2);
void displayDistance(double distance);
void displayMidPoint(double mid1 , double mid2);
int main()
{
double x1, x2, y1, y2;
double distance;
cout << "Enter the first x and y coordinates: ";
cin >> x1 >> y1;
cout << "Enter the second x and y coordinates: ";
cin >> x2 >> y2;
double distancex = (x2 - x1)^2;
double distancey = (y2 - y1)^2;
double calcdistance = sqrt(distancex - distancey);
return distance;
displayDistance(distance);
double mid1= x1+x2/2;
double mid2= y1+y2/2;
displayMidPoint(double mid1 , double mid2);
system("pause");
return 0;
}
void displayDistance(double distance)
{
cout << "The distance between the two points is: " << distance << endl;
}
void displayMidPoint(double mid1, double mid2)
{
cout << "The mid point between two points is : " << (mid1,mid2) << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.