Answer to Question #24421 in C++ for redrose

Question #24421
Write, compile and execute a C++ program that calculates the distance between two points whose coordinates are (7, 12) and (3, 9). Use the fact that the distance between two points having coordinates (x1, y1) and (x2, y2) is distance = sqrt ([x1 - x2]2 + [y1 - y2]2). When you have verified that your program works correctly, by calculating the distance between the two points manually, use your program to determine the distance between the points (-12, -15) and (22, 5).
1
Expert's answer
2013-02-18T12:12:43-0500
#include <cmath>
#include <conio.h>
#include <iostream>

using namespace std;

double distance(double x1, double y1, double x2, double y2)
{
return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}

int main()
{
cout << "The distance between points (7, 12) and (3, 9) is: "
<< distance(7, 12, 3, 9) << endl;
cout << "The distance between points (-12, -15) and (22, 5) is: "
<< distance(-12, -15, 22, 5) << endl;

_getch();
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS