This is a C++ question: In mathematics, the distance between one point (A) and a
ID: 3813803 • Letter: T
Question
This is a C++ question: In mathematics, the distance between one point (A) and another point (B), each with coordinates (x,y), can be computed by taking the differences of their x coordinates and their y coordinates and then squaring those differences. The squares are added and the square root of the resulting sum is taken and... voila! The distance. Given two variables , p1 and p2 that are of type POINT -- a structured type with two fields, x and y, both oftype double -- write an expression whose value is the distance between the two points represented by p1 and p2.
Explanation / Answer
Assuming Point is declared through typedef in below way:::
typedef struct Point {
double x,y;
} Point;
Code will be =>
Point a, b;
double distance = sqrt( pow(a.x - b.x, 2) + pow(a.y - b.y, 2) );
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.