In mathematics, the distance of a point with coordinates (x,y) from the origin is the square root of the sum of x-squared and y-squared. Assume that Point has already been defined as a structured type with two double fields, x and y, define a function getR that takes as an argument a value of type Point and returns the distance of that point from the origin (as described above).
LANGUAGE: C++
CHALLENGE:
In mathematics, the distance of a point with coordinates (x,y) from the origin is the square root of the sum of x-squared and y-squared. Assume that Point has already been defined as a structured type with two double fields, x and y, define a function getR that takes as an argument a value of type Point and returns the distance of that point from the origin (as described above).
SOLUTION:
double getR (Point p1){ return sqrt( (p1.x )*(p1.x) + (p1.y)*(p1.y)); }