| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 859 人关注过本帖
标题:[求助]单向链表编的成绩系统
只看楼主 加入收藏
yz1987cn
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2006-3-5
收藏
 问题点数:0 回复次数:3 
[求助]单向链表编的成绩系统

05级《C语言程序设计》实验报告题目

已知N个学生的学号和4门功课的成绩,计算:

1)每个学生的总分、平均分和每门课程的平均分。

2)按总分从大到小排序,同时调整学号、4门功课成绩和平均分;输出经排序后全部学生的成绩单。

3)任意输入一个学生的学号,输出该学生的成绩单。

注:每一小题用一个函数完成。
哪里有错,希望会的人指出错误.
#include"stdio.h"
#include"conio.h"
#define LEN sizeof(struct student)
typedef struct student
{
long number;
float sc[4];
struct student *next;
};
student *head=NULL;
int count=0;/*全局变量,节点个数,即学生人数*/
struct student *create();
void f1(int x);
void f2(int y);
void f3(int z);
void main()
{
clrscr();
creat();/*创建链表*/
f1();/*满足要求1的函数*/
f2();/*满足要求2的函数*/
f3();/*满足要求3的函数*/
}
struct student *create()
{
struct student *head=NULL,*new,*tail;
new=tail=(struct student *)malloc(LEN);
print("please input the data:\n");
scanf("%ld%f%f%f%f",&new->number,&new->sc[0],&new->sc[1],&new->sc[2],&new->sc[3],);
while(new->number)
{count++;
if(count==1) head=new;
else tail->next=new;
tail=new;
new=(struct student *)malloc(LEN);
scanf("%ld%f%f%f%f",&new->number,&new->sc[0],&new->sc[1],&new->sc[2],&new->sc[3],);
}
tail->next=NULL;
return head;
}
void f1()
{
student *p=head;
float num0=num1=num2=num3=0;
while(p!=NULL)
{
num0+=p->sc[0];num1+=sc[1];num2+=sc[2];num3+=sc[3];
p=->next;
}
p=head;
while(p!=NULL)
{
printf("xuehao------zongfen--pingjunfen--ave1--ave2--ave3--ave4\n");
printf("%ld--%f----%f---%f---%f---%f---&f",p->number,p->sc[0]+p->sc[1]+p->sc[2]+p->sc[3],(p->sc[0]+p->sc[1]+p->sc[2]+p->sc[3])/4,num0/4,num1/4,num2/4,num3/4)
p=p->next;
}
printf("press any key to continue\n");
gatch();
}
void f2()
{
struct stu
{
long number;
float num;ave;sc[4];
}s[count];
student *p=head;
int i,j;
float k;
for(i=0;p!=NULL&&i<count;p=p->next,i++)
{
s[i]->number=p->number;s[i]->num=p->sc[0]+p->sc[1]+p->sc[2]+p->sc[3];s[i]->ave=(p->sc[0]+p->sc[1]+p->sc[2]+p->sc[3])/4;s[i]->sc[0]=p->sc[0];s[i]->sc[1]=->p->sc[1];s[i]->sc[2]=->p->sc[2];s[i]->sc[3]=->p->sc[3];
}
for(i=0;i<count-1;i++)
{
for(j=i+1;j<count;j++)
if(s[i]->num<s[j]->num)
{k=s[i]->num;s[i]->num=s[j]->num;s[j]->num=k;
k=s[i]->number;s[i]->number=s[j]->number;s[j]->number=k;
k=s[i]->ave;s[i]->ave=s[j]->ave;s[j]->ave=k;
k=s[i]->sc[0];s[i]->sc[0]=s[j]->sc[0];s[j]->sc[0]=k;
k=s[i]->sc[1];s[i]->sc[1]=s[j]->sc[1];s[j]->sc[1]=k;
k=s[i]->sc[2];s[i]->sc[2]=s[j]->sc[2];s[j]->sc[2]=k;
k=s[i]->sc[3];s[i]->sc[3]=s[j]->sc[3];s[j]->sc[3]=k;
}
printf("the data checked is:\n");
printf("%ld--%f----%f---%f---%f---%f---&f:\n")
for(i=0;i<count,i++)
printf("%ld--%f----%f---%f---%f---%f---&f\n",s[i]->number,s[i]->num,s[i]->ave,s[i]->sc[0],s[i]->sc[1],s[i]->sc[2],k=s[i]->sc[3]");
gatch();
}
void f3()
{
student *p=head;
int find=0;
long number;
do
{
clrscr();
printf(input the number of the student you want:\n);
scanf("%ld",&number);
for(;p!=NULL;p=p->next)
if(number==p->number)
{
printf("xuehao------zongfen--pingjunfen--sc1--sc2--sc3--sc4\n");
printf("%ld--%f----%f---%f---%f---%f---&f",p->number,p->sc[0]+p->sc[1]+p->sc[2]+p->sc[3],(p->sc[0]+p->sc[1]+p->sc[2]+p->sc[3])/4,p->sc[0],p->sc[1],p->sc[2],p->sc[3]);
}
printf("press the space key to continue,other keys to exit!")
}
while(gatch()==' ');
}

搜索更多相关主题的帖子: 链表 Roman Times 
2006-06-04 02:21
feng1256
Rank: 4
等 级:贵宾
威 望:14
帖 子:2899
专家分:0
注 册:2005-11-24
收藏
得分:0 

经常说自定义函数名第一个字母要大写(为了与库函数区别)
变量和函数名起名最好能望文生义。
new也别随便当变量用(C++中的关键字)
函数名有拼写错误
head既然是全局变量就不用返回,而且你重复定义
建立链表部分判断申请的内存指针是都为NULL总需要吧
函数声明定义最好用标准形式,而且你这不正确
typedef你这个用在那作用何在?你也没起别名!把结构体指针别名为Linklist 也好啊
没看见任何释放申请内存的操作!

大概看到的一点问题(我没仔细看全)!楼主仔细看看,先改改再说!



叁蓙大山:工謪、稅務、嗣發 抱歉:不回答女人的问题
2006-06-04 05:59
feng1256
Rank: 4
等 级:贵宾
威 望:14
帖 子:2899
专家分:0
注 册:2005-11-24
收藏
得分:0 
printf() 中的引号你都省了!我暂时不看了 问题太多

叁蓙大山:工謪、稅務、嗣發 抱歉:不回答女人的问题
2006-06-04 06:02
yz1987cn
Rank: 1
等 级:新手上路
帖 子:49
专家分:0
注 册:2006-3-5
收藏
得分:0 

谢谢了,我再 好好改改 ,这帖子可以先删了去,不好意思


潘安退避三舍,宋玉甘拜下风
2006-06-04 09:59
快速回复:[求助]单向链表编的成绩系统
数据加载中...
 
   



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

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