*** C++ only, Every code researched so far keeps adding 'sprt' but the system rejects it. If I need that (try to avoid if possible) then I also need to know how to add 'sprt' to be a called upon variable.
Determine the distance between point (x1, y1) and point (x2,
y2), and assign the result to pointsDistance. The calculation
is:
Distance=(x2−x1)2+(y2−y1)2
Ex: For points (1.0, 2.0) and (1.0, 5.0), pointsDistance is
3.0.
code-------------------------------------------
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x1;
double y1;
double x2;
double y2;
double xDist;
double yDist;
double pointsDistance;
xDist = 0.0;
yDist = 0.0;
pointsDistance = 0.0;
cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;
/* Your solution goes here */
cout << pointsDistance << endl;
return 0;
}
/* WITHOUT SQRT*/
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x1;
double y1;
double x2;
double y2;
double xDist;
double yDist;
double pointsDistance;
xDist = 0.0;
yDist = 0.0;
pointsDistance = 0.0;
cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;
/* Your solution goes here */
pointsDistance = (double)(pow(x2-x1,2)+pow(y2-y1,2));
double sqrt = pointsDistance / 2;
int temp = 0;
while(sqrt != temp){
temp = sqrt;
sqrt = ( pointsDistance/temp + temp) / 2;
}
pointsDistance = sqrt;
cout << pointsDistance << endl;
return 0;
}
/* WITH SQRT */
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x1;
double y1;
double x2;
double y2;
double xDist;
double yDist;
double pointsDistance;
xDist = 0.0;
yDist = 0.0;
pointsDistance = 0.0;
cin >> x1;
cin >> y1;
cin >> x2;
cin >> y2;
/* Your solution goes here */
pointsDistance =
(double)sqrt(pow(x2-x1,2)+pow(y2-y1,2));
cout << pointsDistance << endl;
return 0;
}
/* PLEASE UPVOTE */
Get Answers For Free
Most questions answered within 1 hours.