1、学生信息管理系统C语言实现#include#include#includeint input(struct studcode *);/输入学生信息的函数void instruct(void); /打印提示信息void picture();/制表函数void output(struct studcode *);/输出函数void search(struct studcode *);/查找信息函数int increase(struct studcode *);/增加学生信息的函数void dele(struct studcode *);/删除学生记录的函数void printall(struct
2、studcode *);/输出全部学生信息的函数void average(struct studcode *headp,struct analysis *head );/统计各科目平均分int sort(struct analysis *head);/排序函数(升序排列)void date_load(struct studcode *headp);/程序开始载入信息void date_save(struct studcode *headp);/程序结束保存数据struct analysis char name_ex20;/实验名称 int number; /统计到课人数 float aver;
3、/平均分 struct analysis *next;struct student char name_tea20;/教师名字 char name_stu20;/学生名字 char clas20;/班级 char name_ex20;/实验名称 float match;/分数;struct studcode struct student date; struct studcode *next;/建立链表的指针;int main() char choose; struct studcode *head=NULL; struct analysis *head1=NULL; /date_load(&
4、head); instruct(); printf(n请选择功能:); choose=getchar(); while(choose!=0)/输入0结束程序 switch(choose) case 1: input(&head);/建立链表 getchar(); getchar(); break; case 2: search(head);/查找信息 getchar(); getchar(); break; case 3: dele(&head);/删除信息 getchar(); getchar(); break; case 4: increase(head);/增加信息 getchar();
5、 getchar(); break; case 5: printall(head);/输出全部信息 getchar(); getchar(); break; case 6: average( head,&head1 );/统计各科平均分并升序输出 getchar(); getchar(); break; default: printf(n 选择错误,重选 n); instruct(); printf(n请选择功能:); choose=getchar(); system(cls); date_save(head); printf(谢谢使用本系统n); return 0; void instruc
6、t(void) system(cls); printf(nttt 试验管理系统 tttt ); printf(nttt 1 建立学生信息链表tttt ); printf(nttt 2 搜索学生相关信息tttt ); printf(nttt 3 删除某个学生信息tttt ); printf(nttt 4 增加某个学生信息tttt ); printf(nttt 5 输出链表全部信息tttt ); printf(nttt 6 统计各科目平均分tttt ); printf(nttt 0 退出程序 tttt ); int input(struct studcode *headp) struct stud
7、code *p ,*tail; char a4; system(cls); date_load(headp); if(*headp!=NULL) printf(链表信息载入成功); return 1; else printf(目前没有数据保存请从终端输入数据); printf(nttt 成绩输入功能 tttt ); p=(struct studcode *)malloc(sizeof(struct studcode ); if(p=NULL) printf(error); exit(-1); printf(n请按提示输入相关信息); printf(n教师姓名:); scanf(%s,p-dat
8、e.name_tea); printf(学生姓名:); scanf(%s,p-date.name_stu); printf(学生班级:); scanf(%s,p-date.clas); printf(实验名称:); scanf(%s,p-date.name_ex); printf(评分:); scanf(%f,&p-date.match); p-next=*headp; *headp=p; tail=p; printf(是否继续输入 输入NO退回主菜单 其他任意字符继续当前操作 ); scanf(%s,a); while(strcmp(a,NO)!=0) system(cls); printf
9、(nttt 成绩输入功能 tttt ); p=(struct studcode *)malloc(sizeof(struct studcode); if(p=NULL) printf(error); exit(-1); printf(n教师姓名:); scanf(%s,p-date.name_tea); printf(学生姓名:); scanf(%s,p-date.name_stu); printf(学生班级:); scanf(%s,p-date.clas); printf(实验名称:); scanf(%s,p-date.name_ex); printf(评分:); scanf(%f,&p-d
10、ate.match); p-next=NULL; tail-next=p; tail=p; printf(是否继续输入 输入NO退回主菜单 其他任意字符继续当前操作 ); scanf(%s,a); return 1;void search(struct studcode *headp) int flag=1; char a220,b4=YES; struct studcode *p; system(cls); printf(nttt 成绩查询功能 tttt ); while(!strcmp(b,YES) p=headp; printf(n学生姓名:); scanf(%s,a0); printf
11、(实验名称:); scanf(%s,a1); for(;p!=NULL;p=p-next) flag=1; if(strcmp(a0,p-date.name_stu)=0&strcmp(a1,p-date.name_ex)=0) flag=0; picture(); output(p); break; if(flag=1) printf(n请确认您输入的姓名或者实验名称是否正确); printf(n是否要继续使用该功能 YES/NO ); scanf(%s,b); system(cls); printf(nttt 成绩查询功能 tttt ); void picture() printf(ttt
12、 实验成绩表); printf(n 教师姓名 学生姓名 学生班级 实验名称 实验成绩); void output(struct studcode *p) printf(n %14s %13s %8s %19s%8.2f,p-date.name_tea,p-date.name_stu,p-date.clas,p-date.name_ex,p-date.match);void dele(struct studcode *headp) struct studcode *p,*last; char a20,b20,c5=YES; system(cls); while(strcmp(c,YES)=0)
13、printf(学生姓名); scanf(%s,a); printf(实验名称); scanf(%s,b); p=*headp; while(strcmp(a,p-date.name_stu)!=0 & strcmp(b,p-date.name_ex)!=0 & p-next!=NULL) last=p; p=p-next; if(strcmp(a,p-date.name_stu)=0 & strcmp(b,p-date.name_ex)=0) if(p=*headp) *headp=p-next; else last-next=p-next; free(p); else printf(请确认您
14、输入的姓名或者实验名称是否正确); printf(输入YES继续使用该功能,输入其他任意字符退回主菜单 ); scanf(%s,c); system(cls); void printall(struct studcode *headp) char a5; system(cls); picture(); if(headp!=NULL) output(headp); headp=headp-next; while(headp!=NULL) output(headp); headp=headp-next; printf(n输入back返回主菜单); while(strcmp(a,back)!=0)
15、scanf(%s,a); void average(struct studcode *headp,struct analysis *head ) char a5; struct analysis *p=*head; system(cls); if(headp=NULL) printf(请先建立链表); exit(-1); p=*head; while(p!=NULL) p-aver=0; p=p-next; p=*head; while(headp!=NULL) while(strcmp(headp-date.name_ex,p-name_ex)!=0) p=p-next; p-aver+=h
16、eadp-date.match; p=*head; headp=headp-next; while(p!=NULL) p-aver/=p-number; p=p-next; p=*head; sort(head);/求出平均值后排序 while(p!=NULL) printf(%s平均分为%fn,p-name_ex,p-aver); p=p-next; printf(输入back退回主菜单); scanf(%s,a); while(strcmp(a,back) scanf(%s,a); int sort(struct analysis *head) int n=0,i,m,temp1; flo
17、at temp2; struct analysis *p,*j; char temp320; p=*head; j=p-next; if(j=NULL) return 0;/如果只有一个科目的数据则不排序 while(p!=NULL)/统计有几个科目,作为下面冒泡排序控制条件的依据 n+=1; p=p-next; p=*head; for(i=0;inext;maverj-aver)/排序时直接交换各节点数据 strcpy(temp3,p-name_ex);/交换实验名称 strcpy(p-name_ex,j-name_ex); strcpy(j-name_ex,temp3); temp1=p
18、-number;/交换到课人数 p-number=j-number; j-number=temp1; temp2=p-aver; p-aver=j-aver; j-aver=temp2; p=j; j=j-next; return 1;void date_load(struct studcode *headp) char ch; FILE *f; struct studcode *p,*tail; if(f=fopen(e:input.txt,a+)=NULL) printf(error); exit(0); ch=fgetc(f);/读取第一个空格,控制格式 if(ch!=EOF)/如果文件
19、中有保存的信息则读取 if(p=(struct studcode*)malloc(sizeof(struct studcode)=NULL) printf(error); exit(0); fscanf(f,%s %s %s %s %fn,p-date.name_tea,p-date.name_stu,p-date.clas,p-date.name_ex,&p-date.match); p-next=NULL; *headp=p; tail=p; while(!feof(f) if(p=(struct studcode*)malloc(sizeof(struct studcode)=NULL)
20、 printf(error); exit(0); fscanf(f, %s %s %s %s %fn,p-date.name_tea,p-date.name_stu,p-date.clas,p-date.name_ex,&p-date.match); p-next=NULL; tail-next=p; tail=p; fclose(f);void date_save(struct studcode *headp) FILE *f; struct studcode *p; int i; printf(是否要更新原有数据。 输入1进行更新,其他数字跳过更新步骤:); scanf(%d,&i); i
21、f(i=1)/跟新数据的模块 if(f=fopen(e:input.txt,w)=NULL) printf(error); exit(0); p=headp; while(p!=NULL) fprintf(f, %s %s %s %s %fn,p-date.name_tea,p-date.name_stu,p-date.clas,p-date.name_ex,p-date.match); p=p-next; fclose(f); int increase(struct studcode *headp) char a4=YES; struct studcode *p; system(cls);
22、if(headp=NULL) printf(请先创建链表); return 1; while(headp-next!=NULL) headp=headp-next; while(strcmp(a,YES)=0) if(p=(struct studcode*)malloc(sizeof(struct studcode)=NULL) printf(error); exit(1); printf(教师姓名:); scanf(%s,p-date.name_tea); printf(学生姓名:); scanf(%s,p-date.name_stu); printf(学生班级:); scanf(%s,p-date.clas); printf(实验名称:); scanf(%s,p-date.name_ex); printf(评分:); scanf(%f,&p-date.match); p-next=NULL; headp-next=p; headp=p; printf(是否继续增加记录 输入YES继续增加,输入其他任意字符退回主菜单); scanf(%s,a); system(cls); return 1;
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1