首页 新闻 会员 周边

编程新手想问各路大神下面程序哪里有问题,为什么结果是一个奇葩数?

0
悬赏园豆:10 [已解决问题] 解决于 2016-04-03 09:02
#include<iostream>
using namespace std;
class point
{
public:
    point(double a, double b,double c,double d);
    friend void dist(point*p);
    void show();
private:
    double u;
    double w;
    double x;
    double y;
    double z;
};
point::point(double a, double b, double c, double d )
{
    u = a;
    w = b;
    x = c;
    y = d;
}
void dist(point*p)
{
    p->z=sqrt((p->u -p->x)*(p->u -p-> x)+(p->w -p->y)*(p->w -p->y));
    
}
void point::show()
{
    cout << "the distance of the two point is:" << z << endl;
}
int main()
{
    point chih(8,6,4,2);
    point *p;
    p = &chih;
    chih. show();
}
爱是用心码不要说话的主页 爱是用心码不要说话 | 初学一级 | 园豆:154
提问于:2016-04-02 17:58
< >
分享
最佳答案
0

你忘了调用dist(p);

int main()
{
    point chih(8, 6, 4, 2);
    point *p;
    p = &chih;
    dist(p);
    chih.show();
}

 

收获园豆:10
arcsinW | 菜鸟二级 |园豆:214 | 2016-04-02 23:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册