求c语言版数据结构课题 学生成绩管理系统的程序

2024-12-15 21:24:22
推荐回答(1个)
回答1:

#include
#include"malloc.h"
#include"string.h"
struct stu{
char name[20];
char stuno[10];
int yw;
int sx;
int yy;
};
struct link{
stu *astu;
link *next;
};
void printfile(link *head,char *s)
{
FILE *p=fopen(s,"w");
link *temp=head;
fprintf(p,"姓名\t学号\t语文\t数学\t英语\n");
while(temp->next!=NULL)
{
temp=temp->next;
fprintf(p,"%s\t%s\t%d\t%d\t%d\n",temp->astu->name,temp->astu->stuno,temp->astu->yw,temp->astu->sx,temp->astu->yy);
}
fclose(p);
}
link *getlink(char *s)
{
FILE *p=fopen(s,"r");
link *head=(link *)malloc(sizeof(link));
int pf;
head->astu=NULL;
head->next=NULL;
link *tail=head;
stu *temp;
fseek(p,sizeof("姓名\t学号\t语文\t数学\t英语\n"),0);
while(!feof(p))
{
pf=ftell(p);
temp=(stu *)malloc(sizeof(stu));
fscanf(p,"%s\t%s\t%d\t%d\t%d\n",temp->name,temp->stuno,&(temp->yw),&(temp->sx),&(temp->yy));
if(pf==ftell(p))break;
tail->next=(link *)malloc(sizeof(link));
tail=tail->next;
tail->astu=temp;
tail->next=NULL;
}
fclose(p);
return head;
}
int allscore(stu *astu)
{
return astu->sx+astu->yw+astu->yy;
}
bool fail(stu *astu)
{
return astu->sx<60||astu->yw<60||astu->yw<60;
}
link *input(char *s)
{
link *head=(link *)malloc(sizeof(link));
head->astu=NULL;
head->next=NULL;
link *tail=head;
stu *temp;
while(true)
{
temp=(stu *)malloc(sizeof(stu));
printf("请输入学生姓名或者输入0结束:");
scanf("%s",temp->name);
if(strcmp(temp->name,"0")==0)break;
printf("请输入学生学号:");
scanf("%s",temp->stuno);
printf("请输入学生语文成绩:");
scanf("%d",&(temp->yw));
printf("请输入学生数学成绩:");
scanf("%d",&(temp->sx));
printf("请输入学生英语成绩:");
scanf("%d",&(temp->yy));
tail->next=(link *)malloc(sizeof(link));
tail=tail->next;
tail->astu=temp;
tail->next=NULL;
}
printfile(head,s);
printf("已成功保存至文件%中\n",s);
return head;
}
void main()
{
link *p1,*p2,*p3,*p4,*temp1,*temp2,*temp3,*temp4;
stu *temp;
printf("请输入1.txt中的数据:\n");
input("1.txt");
printf("请输入2.txt中的数据:\n");
input("2.txt");
char s[20];
p1=getlink("1.txt");
p2=getlink("2.txt");
temp1=p1;
while(temp1->next!=NULL)temp1=temp1->next;
temp1->next=p2->next;
for(temp1=p1->next;temp1!=NULL;temp1=temp1->next)
for(temp2=temp1->next;temp2!=NULL;temp2=temp2->next)
if(allscore(temp1->astu)astu))
{
temp=temp1->astu;
temp1->astu=temp2->astu;
temp2->astu=temp;
}
printfile(p1,"3.txt");
temp1=p1;
for(temp2=p1->next;temp2!=NULL;temp2=temp2->next)
if(fail(temp2->astu))
{
temp1->next=temp2;
temp1=temp2;
}
temp1->next=NULL;
printfile(p1,"4.txt");
p1=getlink("3.txt");
printf("结果已保存至文件\n");
printf("请输入要寻找的学生姓名:");
scanf("%s",s);
for(temp1=p1->next;temp1!=NULL;temp1=temp1->next)
if(strcmp(temp1->astu->name,s)==0)
printf("%s\t%s\t%d\t%d\t%d\n",temp1->astu->name,temp1->astu->stuno,temp1->astu->yw,temp1->astu->sx,temp1->astu->yy);
}