| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 450 人关注过本帖
标题:看不懂这编译结果
只看楼主 加入收藏
rony
Rank: 1
等 级:新手上路
帖 子:10
专家分:0
注 册:2007-4-6
收藏
 问题点数:0 回复次数:1 
看不懂这编译结果

求教各位大虾,有道题不大会,又不知错哪了帮我看一下这道题啊...谢谢!
定义一个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)

搜索更多相关主题的帖子: average include public 平均值 count 
2007-04-06 13:18
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

main上面差个}


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2007-04-06 14:38
快速回复:看不懂这编译结果
数据加载中...
 
   



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

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