首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

小弟我编的程序哪儿错了,大家帮小弟我指指啊多谢

2012-05-09 
我编的程序哪儿错了,大家帮我指指啊。。。谢谢class point{public:point(float xx0,float yy0){xxxyyy}

我编的程序哪儿错了,大家帮我指指啊。。。谢谢
class point
{
public:
point(float xx=0,float yy=0)
{
x=xx;
y=yy;
}
float getx()
{
return x;
}
float gety()  
{
return y;
}
friend float linefit(point 1_point[],int n_point); //友元函数

private:
float x,y;
};

#include<iostream.h>
#include<math.h>
#include"point.h"

float linefit(point 1_point[],int n_point) //友元函数体
{
float av_x,av_y;
float L_xx,L_yy,L_xy;
//变量初始化
av_x=0; //x的平均值  
av_y=0; //y的平均值 
L_xx=0 //Lxx
  L_yy=0 //Lyy
L_xy=0 //Lxy
for(int i=0;i<n_point;i++) //计算X,y的平均值
{
av_x+=1_point[i].x/n_point;
av_y+=1_point[i].y/n_point;
}

for(i=0;i<n_point;i++) //计算Lxx,Lyy,Lxy
{
L_xx+=(1_point[i].x-av_x)*(1_point[i].x-av_x);
L_yy+=(1_point[i].y-av_y)*(1_point[i].y-av_y);
L_xy+=(1_point[i].x-av_x)*(1_point[i].y-av_y);
 
}
cout<<"this line can be fitted by y=ax+b."<<endl;
cout<<"a="<<L_xy/L_xx; //输出回归系数a
cout<<"b="<<av_y-L_xy*av_x/L_xx<<endl; // 输出回归系数b
return float(L_xy/sqrt(L_xx*Lyy)); //返回相关系数r


}
void main()
{
point 1_p[10]={point(6,10),point(14,20),point(26,30),point(33,40),
point(46,50),point(54,60),point(67,70),point(75,80),point(84,90),point(100,100)}; //初始化数据点
float r=linefit(1_p,10);
cout<<"line coefficient r="<<r<<endl; //输出相关系数


}

错误提示是:point.h(17) : error C2059: syntax error : 'bad suffix on numbe
error C2143: syntax error : missing ')' before 'constant'
point.h(17) : error C2143: syntax error : missing ';' before 'constant'
point.h(17) : error C2059: syntax error : 'constant'
point.h(17) : error C2059: syntax error : ')'
point.h(17) : error C2238: unexpected token(s) preceding ';'
main.cpp(5) : error C2059: syntax error : 'bad suffix on number'
main.cpp(5) : error C2143: syntax error : missing ')' before 'constant'
main.cpp(5) : error C2143: syntax error : missing ';' before 'constant'
main.cpp(5) : fatal error C1004: unexpected end of file found

[解决办法]


#include<iostream>
#include<math.h>
#include"point.h"

放到开始
[解决办法]
1_point...这个变量的命名有误,不能用数字开头
[解决办法]

C/C++ code
    L_xx=0; //Lxx        L_yy=0; //Lyy        L_xy=0; //Lxy这儿缺少三个分号
[解决办法]
C/C++ code
return float(L_xy/sqrt(L_xx*L_yy)); //这儿的L_yy写错了point p_1//这儿的变量定义有类似的错误 

热点排行