跪求c语言编程学生成绩管理源代码 那位高手行行好
发布网友
发布时间:2022-04-24 04:21
我来回答
共1个回答
热心网友
时间:2023-04-24 15:12
#include"stdio.h"
#include"stdlib.h"
#define N 3
struct student
{
char name[10];
char num[20];
int score[3];
int sum;
float ave;
struct student *next;
}stu[N];
struct student *creat()
{
int i;
struct student *h=NULL,*p;
for(i=0;i<N;i++)
{
p=(struct student *)malloc(sizeof(struct student));
printf("please input number,name,score1,score2,score3:\n");
scanf("%s%s%d%d%d",stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
p->sum=stu[i].score[0]+stu[i].score[1]+stu[i].score[2];
p->ave=((float)p->sum)/3;
p->next=h;
h=p;
}
return h;
}
void print(struct student *h)
{
struct student *p;
p=h;
while(p!=NULL)
{
printf("%s,%s,%d,%d,%d,%d,%f\n",p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->ave);
p=p->next;
}
}
struct student *sort(struct student *h)
{
struct student *h1,*p,*q,*t;
h1=h->next;
h->next=NULL;
while(h1)
{
t=h1;
h1=h1->next;
p=h;
q=h;
while(t->sum<p->sum&&p)
{q=p;p=p->next;}
if(p==h)
{
t->next=p;
h=t;
}
else
{
t->next=p;
q->next=t;
}
}
return h;
}
void filesave(struct student *h)
{
struct student *p;
p=h;
FILE *fp;
if((fp=fopen("abcd.txt","wb"))==NULL)
{
printf("file cann't be opened!\n");
exit(0);
}
while(p)
{
fwrite(p,sizeof(struct student),1,fp);
p=p->next;
}
printf("data have been writeen to the file!\n");
}
void printthreescore(struct student *h)
{
struct student *p=h;
while(p)
{
printf("zong cheng ji:%d\n",p->sum);
p=p->next;
}
}
void printbjg(struct student *h)
{
struct student *p=h;
while(p)
{
if(p->score[0]<60||p->score[1]<60||p->score[2]<60)
printf("%s,%s,%d,%d,%d,%d,%f",p->num,p->name,p->score[0],p->score[1],p->score[2],p->sum,p->ave);
p=p->next;
}
}
main()
{
struct student *creat();
void print(struct student *h);
struct student *sort(struct student *h);
void filesave(struct student *h);
void printthreescore(struct student *h);
void printbjg(struct student *h);
struct student *h,*h1;
h=creat();
printf("shu ru de xue sheng xin xi ru xia:\n");
print(h);
printthreescore(h);
printbjg(h);
filesave(h);
h1=sort(h);
print(h1);
}