| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2094 人关注过本帖
标题:当没加#ifndef_POINT_H #define_POINT_H #endif 时,项目可以运行,加了后 ...
取消只看楼主 加入收藏
Arther0919
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2019-9-11
结帖率:100%
收藏
已结贴  问题点数:20 回复次数:2 
当没加#ifndef_POINT_H #define_POINT_H #endif 时,项目可以运行,加了后就显示无效预处理。不懂,求助大神
//point.h
#ifndef_POINT_H
#define_POINT_H
class Point{
public:
    double getX() const{                                                  //规定为const函数
        return x;
    };
    double getY() const{
        return y;
    };
    Point(double newx = 0, double newy = 0):x(newx)    ,y(newy){}
    Point(){
        x = 0;
        y = 0;
    }

private:
    double x, y;
};                       //不要忘记分号
#endif
//.cpp
#include <iostream>
#include <cmath>
#include "point.h"

using namespace std;

double LineFit(const Point points[], int npoint){
    double aX = 0, aY = 0;
    double lxx = 0, lyy = 0, lxy = 0;
    for(int i = 0; i < npoint; i++){
        aX += points[i].getX()/npoint;
        aY += points[i].getY()/npoint;
    }
    for(int i = 0; i < npoint; i++){
        lxx += (points[i].getX() - aX)*(points[i].getX() - aX);
        lyy += (points[i].getY() - aY)*(points[i].getY() - aY);
        lxy += (points[i].getY() - aY)*(points[i].getX() - aX);
    }
    cout << "This line can be fixxed by y=ax+b" << endl;
    cout << "a = " << lxy/lyy << endl;
    cout << "b = " << aY - lxy*aX/lxx << endl;
    return static_cast<float>(lxy/sqrt(lxx*lyy));
}

int main()
{
    Point points[3] = {Point(3,3), Point(4,4), Point(5,5)};
    float r = LineFit(points, 3);
    cout << "Line  coefficint r = " << r << endl;
    return 0;
}
搜索更多相关主题的帖子: point return int cout double 
2019-09-11 16:00
Arther0919
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2019-9-11
收藏
得分:0 
回复 2楼 rjsp
没用哦
2019-09-11 16:29
Arther0919
Rank: 1
等 级:新手上路
帖 子:9
专家分:7
注 册:2019-9-11
收藏
得分:0 
回复 楼主 Arther0919
没加之前好好的,能编译。一加上就报错无效预处理!
2019-09-11 16:31
快速回复:当没加#ifndef_POINT_H #define_POINT_H #endif 时,项目可以运行,加 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015126 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved