
代碼如下:
#include<iostream>
#include<math.h>
using namespace std;
struct Point{
int x,y,z;
};
void input(Point p){
cout << "Please give your point: ";
cin >> p.x >> p.y >> p.z;
}
void print(Point p){
cout << "(" << p.x << "," << p.y << "," << p.z << ")\n";
}
double cal_dis(Point p1,Point p2){
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y)+(p1.z-p2.z)*(p1.z-p2.z));
}
int main(){
Point p1,p2;
input(p1);
print(p1);
input(p2);
print(p2);
double distance = cal_dis(p1,p2);
cout << "distance= " << distance << "\n";
}
uj5u.com熱心網友回復:
是input那里出現了什么問題么?uj5u.com熱心網友回復:
值傳遞你在函式內部給形參賦值
和實參沒關系
相當于
point p1;
point p = p1;
cin >> p;
cout << p1;
你給p輸入資料 輸出p1卻指望看到p的資料 這是不行的
uj5u.com熱心網友回復:
謝謝!
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/124475.html
標籤:C++ 語言
上一篇:c++
下一篇:下載了包但是載入不進去
