| 网站首页 | 业界新闻 | 小组 | 交易 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
 Reworld，下班在家制作游戏，1500万奖金等你拿 以码会友 以友辅仁

已结贴   问题点数：20  回复次数：4

//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;
}

得分:20
```#ifndef_POINT_H
#define_POINT_H ```

```#ifndef _POINT_H
#define _POINT_H```

得分:0

得分:0

得分:0

#ifndef_POINT_H
#define_POINT_H
#endif
#include <iostream>
#include <cmath>
#include "point.h"

• 5
• 1/1页
• 1