1、include
2、ct studcode **);//删除学生记录旳函数 void printall(struct 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);//程序结束保留数据
3、 struct analysis { char name_ex[20];//试验名称 int number; //记录到课人数 float aver;//平均分 struct analysis *next; }; struct student { char name_tea[20];//教师名字 char name_stu[20];//学生名字 char clas[20];//班级 char name_ex[20];//试验名称 float match;//分数 }; struct studcode {
4、 struct student date; struct studcode *next;//建立链表旳指针 }; int main() { char choose; struct studcode *head=NULL; struct analysis *head1=NULL; //date_load(&head); instruct(); printf("\n请选择功能:"); choose=getchar(); while(choose!='0')//输入0结束程序 { swi
5、tch(choose) { case '1': input(&head);//建立链表 getchar(); getchar(); break; case '2': search(head);//查找信息 getchar(); getchar(); break
6、 case '3': dele(&head);//删除信息 getchar(); getchar(); break; case '4': increase(head);//增长信息 getchar(); getchar(); break; case '5':
7、 printall(head);//输出所有信息 getchar(); getchar(); break; case '6': average( head,&head1 );//记录各科平均分并升序输出 getchar(); getchar(); break; default: printf("\n 选择错误,重选 \n"); }
8、 instruct(); printf("\n请选择功能:"); choose=getchar(); } system("cls"); date_save(head); printf("谢谢使用本系统\n"); return 0; } void instruct(void) { system("cls"); printf("\n\t\t\t 试验管理系统 \t\t\t\t "); printf("\n\t\t\t 1 建立学生信息链表\t\t\t\t "); pri
9、ntf("\n\t\t\t 2 搜索学生有关信息\t\t\t\t "); printf("\n\t\t\t 3 删除某个学生信息\t\t\t\t "); printf("\n\t\t\t 4 增长某个学生信息\t\t\t\t "); printf("\n\t\t\t 5 输出链表所有信息\t\t\t\t "); printf("\n\t\t\t 6 记录各科目平均分\t\t\t\t "); printf("\n\t\t\t 0 退出程序 \t\t\t\t "); } int inpu
10、t(struct studcode **headp) { struct studcode *p ,*tail; char a[4]; system("cls"); date_load(headp); if(*headp!=NULL) { printf("链表信息载入成功"); return 1; } else { printf("目前没有数据保留请从终端输入数据"); } printf("\n\t\t\t 成绩输入功能 \t\t\t\t "); p=(struct studcode *)mall
11、oc(sizeof(struct studcode )); if(p==NULL) { printf("error"); exit(-1); } printf("\n请按提醒输入有关信息"); 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->d
12、ate.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("\n\t\t\t 成绩输入功能 \t\t\t\t "); p=(struct studcode *)malloc(si
13、zeof(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); prin
14、tf("评分:"); scanf("%f",&p->date.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 a[2][20],b[4]="YES"; struct studcode *p; system("cls
15、"); printf("\n┃\t\t\t 成绩查询功能 \t\t\t\t "); while(!strcmp(b,"YES")) { p=headp; printf("\n学生姓名:"); scanf("%s",a[0]); printf("试验名称:"); scanf("%s",a[1]); for(;p!=NULL;p=p->next) { flag=1; if(strcmp(a[0],p->date.name_stu)==0&&strcmp(a[1],p->date.name
16、ex)==0) { flag=0; picture(); output(p); break; } } if(flag==1) { printf("\n请确认您输入旳姓名或者试验名称与否对旳"); } printf("\n与否要继续使用该功能 YES/NO \\\\"); scanf("%s",b); system("cls"); printf("\n\t\t\t 成绩查询功能 \t\t\t\t "); } }
17、 void picture() { printf("\t\t\t 试验成绩表"); 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(str
18、uct studcode **headp) { struct studcode *p,*last; char a[20],b[20],c[5]="YES"; system("cls"); while(strcmp(c,"YES")==0) { 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->nex
19、t!=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("请确认您输入旳姓名或者试验名称与否对旳"); } printf("输入YES继续使用该功能,输入其他任意字符退回主菜
20、单 \\\\"); scanf("%s",c); system("cls"); } } void printall(struct studcode *headp) { char a[5]; system("cls"); picture(); if(headp!=NULL) { output(headp); headp=headp->next; } while(headp!=NULL) { output(headp); headp=headp->next; } printf("\n输入
21、back返回主菜单"); while(strcmp(a,"back")!=0) scanf("%s",a); } void average(struct studcode *headp,struct analysis **head ) { char a[5]; struct analysis *p=*head; system("cls"); if(headp==NULL) { printf("请先建立链表"); exit(-1); } p=*head; while(p!=NULL) { p->aver=0;
22、 p=p->next; } p=*head; while(headp!=NULL) { while(strcmp(headp->date.name_ex,p->name_ex)!=0) { p=p->next; } p->aver+=headp->date.match; p=*head; headp=headp->next; } while(p!=NULL) { p->aver/=p->number; p=p->next; } p=*head; sort(head);//求出平均值后排序
23、 while(p!=NULL) { printf("%s平均分为%f\n",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; float temp2; struct analysis *p,*j; char temp3[2
24、0];
p=*head;
j=p->next;
if(j==NULL)
return 0;//假如只有一种科目旳数据则不排序
while(p!=NULL)//记录有几种科目,作为下面冒泡排序控制条件旳根据
{
n+=1;
p=p->next;
}
p=*head;
for(i=0;i
25、);//互换试验名称 strcpy(p->name_ex,j->name_ex); strcpy(j->name_ex,temp3); temp1=p->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(str
26、uct 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)//假如文献中有保留旳信息则读取 { if((p=(struct studcode*)malloc(sizeof(struct studcode)))==NULL) {
27、 printf("error"); exit(0); } fscanf(f,"%s %s %s %s %f\n",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) {
28、printf("error"); exit(0); } fscanf(f," %s %s %s %s %f\n",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;
29、 int i; printf("与否要更新原有数据。 输入1进行更新,其他数字跳过更新环节:"); scanf("%d",&i); if(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 %f\n",p->date.name_tea,p->date.name_stu,p->date.clas,
30、p->date.name_ex,p->date.match); p=p->next; } fclose(f); } } int increase(struct studcode *headp) { char a[4]="YES"; struct studcode *p; system("cls"); if(headp==NULL) { printf("请先创立链表"); return 1; } while(headp->next!=NULL) headp=headp->next; w
31、hile(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; }






