鱼C论坛

 找回密码
 立即注册
查看: 2167|回复: 3

[已解决]这个程序到底哪里出错了啊???

[复制链接]
发表于 2018-1-26 14:13:32 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#include<iostream>
#include<math.h>
using namespace std;
class point;
class distance
{
private:
    double length;
public:
    distance(double h);
    void qiuhe(point a,point b);
};
class point
{
private:
    double x;
    double y;
public:
    friend class distance;
    point(double a,double b);
};
int main()
{
    point x1(0,0),x2(0,0);
    distance s(1.0);
    s.qiuhe(x1,x2);
    return 0;
}
point::point(double a,double b)
{
    cin>>a>>b;
    x=a;y=b;
}
distance::distance(double h)
{
    length=h;
    cin>>h;
    length=h;
}
void distance::qiuhe(point a,point b)
{
    distance temp(0.0);
    temp=sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
    cout<<temp.length;
}

最佳答案
2018-1-26 17:55:45
using namespace std;
偷懒可不是什么好事

碰巧std命名空间也有一个叫distance这玩意的
#include<iostream>
#include<math.h>

//using namespace std;
class point;

class distance
{
private:
        double length;
public:
        distance(double h);
        void qiuhe(point a, point b);
};

class point
{
private:
        double x;
        double y;
public:
        friend class distance;
        point(double a, double b);
};

int main()
{
        point x1(0, 0), x2(0, 0);
        distance s(1.0);
        s.qiuhe(x1, x2);
        return 0;
}
point::point(double a, double b)
{
        std::cin >> a >> b;
        x = a; y = b;
}
distance::distance(double h)
{
        length = h;
        std::cin >> h;
        length = h;
}
void distance::qiuhe(point a, point b)
{
        distance temp(0.0);
        temp = sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
        std::cout << temp.length;
}
无标题.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-1-26 14:41:15 | 显示全部楼层
感觉好乱,你要习惯类用大写字母开头,同类的函数实现放到一起
还有类方法qiuhe中定义类对象是什么鬼
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-1-26 17:55:45 | 显示全部楼层    本楼为最佳答案   
using namespace std;
偷懒可不是什么好事

碰巧std命名空间也有一个叫distance这玩意的
#include<iostream>
#include<math.h>

//using namespace std;
class point;

class distance
{
private:
        double length;
public:
        distance(double h);
        void qiuhe(point a, point b);
};

class point
{
private:
        double x;
        double y;
public:
        friend class distance;
        point(double a, double b);
};

int main()
{
        point x1(0, 0), x2(0, 0);
        distance s(1.0);
        s.qiuhe(x1, x2);
        return 0;
}
point::point(double a, double b)
{
        std::cin >> a >> b;
        x = a; y = b;
}
distance::distance(double h)
{
        length = h;
        std::cin >> h;
        length = h;
}
void distance::qiuhe(point a, point b)
{
        distance temp(0.0);
        temp = sqrt((a.x - b.x)*(a.x - b.x) + (a.y - b.y)*(a.y - b.y));
        std::cout << temp.length;
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-1-27 09:56:30 | 显示全部楼层
人造人 发表于 2018-1-26 17:55
using namespace std;
偷懒可不是什么好事

谢谢,谢谢!!!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-1 09:44

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表