数据结构课的作业 要求用链表实现学生的学号 姓名 两门课的成绩 同时求出课程的平均成绩

要求用C语言 总体上就是实现学生的平均成绩 跟 两门课程的平均成绩 跪求答案!

这是代码,还有文件
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN sizeof(struct student)
void destroy(struct student* phead);
void print(struct student *pstudent);
struct student
{
char number[11];
char name[10];
char sex[5];
int Cscore;
int Jscore;
int Escore;
struct student *next;
};
void main()
{
struct student *ptemp,*pstudent,*p,*padd,*pbad,*pp;

FILE *pf1,*pf2;

pf1 = fopen("stulist.txt", "r");
if(pf1 == NULL)
{
printf("failed to open file!");
return;
}
pstudent= NULL;
while(!feof(pf1))
{
ptemp = (struct student*)malloc(LEN);
fscanf(pf1,"%s%s%s%d%d%d",ptemp->number,
ptemp->name,
ptemp->sex,
&ptemp->Cscore,
&ptemp->Jscore,
&ptemp->Escore);

ptemp->next = NULL;

if(pstudent== NULL)
pstudent = ptemp;
else
{
ptemp->next = pstudent;
pstudent = ptemp;
}
}
fclose(pf1);
ptemp=pstudent;

while(ptemp!=NULL)
{
if((ptemp->Cscore+ptemp->Jscore+ptemp->Escore)/3>80)
printf("%s\t%s\t%d\n",ptemp->name,ptemp->number,(ptemp->Cscore+ptemp->Jscore+ptemp->Escore)/3);
ptemp=ptemp->next;
}

p=ptemp;
ptemp=pstudent;

pf2 = fopen("studentadd.txt", "r");
if(pf2 == NULL)
{
printf("failed to open file!");
return;
}
while(!feof(pf2))
{
padd = (struct student*)malloc(LEN);
fscanf(pf2, "%s%s%s%d%d%d",padd->number,
padd->name,
padd->sex,
&padd->Cscore,
&padd->Jscore,
&padd->Escore);
}

printf("\n");
while(strcmp(padd->number,ptemp->number)>0)
{
p=ptemp;
ptemp=ptemp->next;
}
if(strcmp(padd->number,ptemp->number)<=0)
{
p->next=padd;
padd->next=ptemp;
}

pbad=pstudent;
pp=pstudent;
while(pbad->Jscore>=70)
{
pp=pbad;
pbad=pbad->next;
}
if(pbad->Jscore<70)
pp->next=pbad->next;

print(pstudent);
destroy(pstudent);

}
void destroy(struct student* phead)
{
struct student *ptemp;
while(phead != NULL)
{
ptemp = phead;
phead = phead->next;
free(ptemp);
}
}
void print(struct student *pstudent)
{

while(pstudent!=NULL)
{
printf("%s\t%s\t%s\t%d\t%d\t%d",pstudent->number,
pstudent->name,
pstudent->sex,
pstudent->Cscore,
pstudent->Jscore,
pstudent->Escore);
printf("\n");
pstudent=pstudent->next;
}
}

文件 新建一个txt文档,命名stulist.txt
0764181057 林婷婷 女 87 90 78
0764181058 刘俊伟 男 99 65 56
0764181060 卢京京 女 80 90 96

再建一个文档,命名studentadd.txt,
0764181059 戴国锋 男 81 92 89
就可以运行

1. 创建一个复杂数据(结构体)类型,该类型的变量能够存放一个学生的信息,包括:学号、姓名、性别以及三门课程的成绩(C程序设计、计算机科学导论和大学英语),要求性别用中文“男/女”表示。
2. 新建链表存放以下三个学生的信息(链表的每一个节点存放一个学生的信息,各节点以学号递增的顺序排列):
0764181057 林婷婷 女 87 90 78
0764181058 刘俊伟 男 99 65 56
0764181060 卢京京 女 80 90 96
3. 列出平均分高于80分的学生姓名,学号和平均成绩,如:
林婷婷 0764181057 85.0
4. 向链表中插入一个学生,插入完成后链表保持学号递增顺序不变,该生信息为:
0764181059 戴国锋 男 81 92 89
5. 从链表中删除“计算机科学导论”课程成绩低于70分的学生。
6.编写一个遍历输出该链表全体数据的函数,并在新建、插入、删除等操作后调用以验证程序的正确性。
这是实现的功能
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-03-26
#include<stdio.h>
struct student
{
int no;
char name[15];
int score[2];
}

main()
{
struct student stu[3];
int i,j,sum;
printf("请输入三个学生信息\n");
for(i=0;i<3;i++)
{
printf("学号:");
scanf("%d",&stu[i].no);
printf("姓名:");
scanf("%s",stu[i].name);
for(j=0;j<2;j++)
{
printf("第%d门成绩\n",j+1);
scanf("%d",&stu[i].score[j]);
}
}
printf("********学生信息*********\n");
printf("学号\t姓名\t第一门成绩\t第二门成绩\n");
for(i=0;i<3;i++)
{
printf("%d\t%s\t",stu[i].no,stu[i].name);
for(j=0;j<2;j++)
printf("%d\t%d",stu[i].score[j]);
printf("\n");
}
sum=stu[0].score[0]+stu[2].score[0]+stu[3].score[0];
printf("第1门课平均成绩为:%d\n",sum/3);
sum=stu[0].score[1]+stu[1].score[1]+stu[2].score[1];
printf("第2门课平均成绩为:%d\n",sum/3);
}