Determine the distance between point x1 y1 and point x2 y2 a

Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to points Distance. The calculation is: Distance = SquareRootOf (x2 - x1)^2 + (y2 - y1)^2 You may declare additional variables. Ex: For points (1.0, 2.0) and (1.0, 5, 0), points Distance is 30.

Solution

#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

int main()
{
double x1,x2,y1,y2;
double pointDistance = 0.0;
double diff1,diff2;


   cout << \"Enter X1 Value\" << endl;
   cin >> x1;
  
  
   cout << \"Enter X2 Value\" << endl;
   cin >> x2;
  
  
   cout << \"Enter Y1 Value\" << endl;
   cin >> y1;
  
  
   cout << \"Enter Y2 Value\" << endl;
   cin >> y2;
  
   diff1 = x2 - x1;
   diff2 = y2 - y1;
  
   pointDistance = sqrt(pow(diff1,2) + pow(diff2,2));
  
   cout << \"Points Distance :\"<< setprecision(1) << fixed << pointDistance <<endl;
  
  
  
   return 0;
}

 Determine the distance between point (x1, y1) and point (x2, y2), and assign the result to points Distance. The calculation is: Distance = SquareRootOf (x2 - x

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site