求教各位大虾,有道题不大会,又不知错哪了帮我看一下这道题啊...谢谢!
定义一个Student类,在该定义中包括:一个数据成员score(分数)及两个静态数据成员total(总分)和学生人数count;成员函数scoretotalcount(float s)用于设置分数,求总分和累计学生认数;静态成员函数sum()用于返回总分:静态成员函数average()求平均值.在main函数中输入某班同学成绩,调用上述函数求全班学生总分和平均分
我自己编了一个程序,可是不知错哪了,请帮帮忙,谢谢!
#include<iostream.h>
class student
{public:
void scoretotalcount(float s);
static float sum();
static float average();
student*next;
private:
float score;
static float total;
static int count;
};
void student::scoretotalcount(float s)
{score=s;total+=score;count++;}
float student::sum()
{return total;}
float student::average()
{float average=total/count;return average;}
void add(student*&f,student*&r,float s)
{student *p=new student;
p->scoretotalcount(s);
p->next=NULL;
if(f==NULL)
{f=r=p;}
else
{r->next=p;r=r->next;}
void main()
{student * front=NULL;student * rear=NULL;
float s;
int choice;
do
{cout<<"请选择是否继续输入"<<endl;
cout<<"输入1继续,\n输入0结束\n";
cin>>choice;
switch(choice)
{case 1:
{ cout<<"输入成绩:";
cin>>s;
add(front,rear,s);
break;
}
case 0:
{break;}
}
cout<<"总分数是:"<<student::sum()<<endl;
cout<<"平均分是:"<<student::average()<<endl;
}while(choice);
}
编译结果如下:
fd.cpp
F:\书籍\fd.cpp(31) : error C2601: 'main' : local function definitions are illegal
F:\书籍\fd.cpp(54) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
fd.obj - 2 error(s), 0 warning(s)