早教吧 育儿知识 作业答案 考试题库 百科 知识分享

C++struct两点间距离Inmathematics,thedistanceofapointwithcoordinates(x,y)fromtheoriginisthesquarerootofthesumofx-squaredandy-squared.AssumethatPointhasalreadybeendefinedasastructuredtypewithtwodoublefields,x

题目详情
C++ struct 两点间距离
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).在数学中点(X,Y)到原点间的距离等于x平方加y平方的平方根.假设这个点已经被定义在一个struct 类型,并有两个double类型的变量X,Y属于其中.定义一个方程getR,此方程作为一个参数值类型Point 并且返回该点到原点的距离.
▼优质解答
答案和解析
#include
#include
#include
using namespace std;
struct point {
\x05 double x; double y;
\x05 };
double getR(struct point p)
{
double d;
d=sqrt(p.x*p.x+p.y*p.y);
return d;
} \x05
int main( )
{
double d;
struct point data;
coutdata.x;
cin>>data.y;
d=getR(data);
cout