永发信息网

请帮忙用C语言制作一个简易的成绩管理系统,感谢大家

答案:1  悬赏:30  手机版
解决时间 2021-12-04 11:49
  • 提问者网友:嗝是迷路的屁
  • 2021-12-03 23:53
请帮忙用C语言制作一个简易的成绩管理系统,感谢大家
最佳答案
  • 五星知识达人网友:街头电车
  • 2021-12-04 00:35
#include #include #include #include typedef struct student{ char num[16]; char name[20]; float score[4]; struct student *next;} stu; stu *head; // 链头指针 stu* create() // 创建链表,从文件读取信息 { printf("Reading student information:\n"); stu *p=NULL; // 指针,指向个待插入的结点 stu *q=NULL; // 指针,用于在其后插入结点 head = NULL; // 一开始链表为空 FILE * r =fopen("input.dat","r"); p = (stu*)malloc(sizeof(stu)); while(fscanf(r,"%s%s%f%f%f",p->num,p->name,&p->score[0],&p->score[1],&p->score[2])!=EOF) { p->score[3]=(p->score[0]+p->score[1]+p->score[2])/3.0; fprintf(stdout,"%s\t%s\t%g\t%g\t%g\t%.2f\n",p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3]); p->next=NULL; if (head == NULL) // head为空,要插入第一个 { head = p; } // 结点,让头指针指向结点p else { // 否则不是头结点,应将p结点 q->next = p; // 插入到q结点的后面 } q = p; // q指向当前最后一个结点 p = (stu*)malloc(sizeof(stu)); } fclose(r); if (head != NULL) { q->next = NULL; // 让q所指的最后一个结点的指针域为空说明这已是链尾了 } return head; // 返回头指针} void sort(stu **head,int n) { FILE *w=NULL; if(n==0) { w = fopen("sortByMath.dat","w"); } else if(n==1) { w = fopen("sortByEnglish.dat","w"); } else if(n==2) { w = fopen("sortByComputer.dat","w"); } else if(n==3) { w = fopen("sortByAvg.dat","w"); } stu *q,*t,*p; stu * new_head = new stu; new_head->next=*head; p=new_head; t=NULL; while(t!=new_head->next) { p=new_head; q=p->next; while(q->next!=t) { if((p->next->score[n]) < (q->next->score[n])) { p->next=q->next; q->next=q->next->next; p->next->next=q; } p=p->next; q=p->next; } t=q; } *head = new_head->next; p = *head; q = p->next; printf("学号\t姓名\t数学\t英语\t计算机\t平均成绩\n"); int grade = 1; while(p!=NULL) { fprintf(w,"%s\t%s\t%g\t%g\t%g\t%.2f\t%d\n", p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3],grade); fprintf(stdout,"%s\t%s\t%g\t%g\t%g\t%.2f\t%d\n", p->num,p->name,p->score[0],p->score[1],p->score[2],p->score[3],grade); if(q!=NULL && q->score[3] < p->score[3]) grade += 1; p=p->next; if(q!=NULL) q=q->next; } printf("\n"); fclose(w);} void count(stu* head){ float cnt[4][8]; int i,j; for(i=0;i<4;i++) { for(j=0;j<8;j++) { if(j!=2)cnt[i][j]=0; else cnt[i][j]=100; } } stu* r=head; while(r!=NULL) { r=r->next; }}int main( ) { head=create(); printf("Sorting by average score:\n"); sort(&head,3); system("pause"); return 0;}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯