亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

想要定義一個方程getR,并且此方程作為一個參數值類型Point并且返回該點到原點的距離?如何實現?

想要定義一個方程getR,并且此方程作為一個參數值類型Point并且返回該點到原點的距離?如何實現?

米脂 2022-05-13 10:11:23
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屬于其中。
查看完整描述

1 回答

?
夢里花落0921

TA貢獻1772條經驗 獲得超6個贊

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
struct point {
double x; double y;
};
double getR(struct point p)
{
double d;
d=sqrt(p.x*p.x+p.y*p.y);
return d;
}
int main( )
{
double d;
struct point data;
cout<<"Please input two double fields, x and y:";
cin>>data.x;
cin>>data.y;
d=getR(data);
cout<<setprecision(6)<<d<<endl;;
system("pause");
return 0;
}



查看完整回答
反對 回復 2022-05-16
  • 1 回答
  • 0 關注
  • 133 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號