学生成绩管理系统 -------------------------------------------------------------------------------- #include "h" /*I/O函数*/#include "h" /*其它说明*/#include "h" /*字符串函数*/#include "h" /*屏幕操作函数*/#include "h" /*内存操作函数*/#include "h" /*字符操作函数*/#include "h" /*动态地址分配函数*/struct score{int mingci;char xuehao[8];char mingzi[20];float score[6];}data,info[1000];int i,j,k=0;char temp[20],ch;FILE *fp,*fp1;void shuru(){if((fp=fopen("s_xt","ab+"))==NULL){ printf("cannot open this "); getch();exit(0);}for(i=0;i<=1000;i++){ printf("Please shuru xuehao:"); gets(xuehao); printf("Please shuru mingzi:"); gets(ingzi); printf("Please shuru yuwen score:"); gets(temp);score[0]=atof(temp); printf("Please shuru shuxue score:"); gets(temp);score[1]=atof(temp); printf("Please input yingyu score:"); gets(temp);score[2]=atof(temp); printf("Please shuru wuli score:"); gets(temp);score[3]=atof(temp); printf("Please shur huaxue score:"); gets(temp);score[4]=atof(temp); score[5]=score[0]+score[1]+score[2]+score[3]+score[4]; fwrite(&data,sizeof(data),1,fp); printf("another?y/n"); ch=getch(); if(ch==n||ch==N) break;} fclose(fp);}void xianshi(){ float s;int n; if((fp=fopen("s_xt","rb+"))==NULL) { printf("Cannot reading this "); exit(0); } for(i=0;i<=1000;i++) { if((fread(&info[i],sizeof(info[i]),1,fp))!=1) break; } printf("xuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen"); for(j=0,k=1;j { info[j]ingci=k; printf("%6s %8s %1f %1f %1f %1f %1f %1f",info[j]xuehao,info[j]ingzi,info[j]score[0],info[j]score[1],info[j]score[2],info[j]score[3],info[j]score[4], info[j]score[5]); } getch(); fclose(fp);}void xiugai(){ if((fp=fopen("s_xt","rb+"))==NULL||(fp1=fopen("xt","wb+"))==NULL) { printf("Cannot open this "); exit(0); } printf("PLease shuru xiugai xuehao:"); scanf("%d",&i); getchar(); while((fread(&data,sizeof(data),1,fp))==1) { j=atoi(xuehao); if(j==i) { printf("xuehao:%smingzi:%s",xuehao,ingzi); printf("Please shuru mingzi:"); gets(ingzi); printf("Please shuru yuwen score:"); gets(temp);score[0]=atof(temp); printf("Please shuru shuxue score:"); gets(temp);score[1]=atof(temp); printf("Please input yingyu score:"); gets(temp);score[2]=atof(temp); printf("Please input wuli score:"); gets(temp);score[3]=atof(temp); printf("Please input huaxue score:"); gets(temp);score[4]=atof(temp); score[5]=score[0]+score[1]+score[2]+score[3]+score[4]; } fwrite(&data,sizeof(data),1,fp1); } fseek(fp,0L,0); fseek(fp1,0L,0); while((fread(&data,sizeof(data),1,fp1))==1) { fwrite(&data,sizeof(data),1,fp); } fclose(fp); fclose(fp1);}void chazhao(){ if((fp=fopen("s_xt","rb"))==NULL) { printf("Cannot open this "); exit(0); } printf("PLease shuru xuehao chakan:"); scanf("%d",&i); while(fread(&data,sizeof(data),1,fp)==1) { j=atoi(xuehao); if(i==j) { printf("xuehao:%s mingzi:%syuwen:%fshuxue:%fyingyu:%fwuli:%fhuaxue:%f",xuehao,ingzi,score[0],score[1],score[2],score[3],score[4],score[5]); }getch(); }}void shanchu(){if((fp=fopen("s_xt","rb+"))==NULL||(fp1=fopen("xt","wb+"))==NULL) { printf("open xt was failed!"); getch(); exit(0); } printf("Please input ID which you want to del:"); scanf("%d",&i);getchar(); while((fread(&data,sizeof(data),1,fp))==1) { j=atoi(xuehao); if(j==i) { printf("Anykey will delet "); getch(); continue; } fwrite(&data,sizeof(data),1,fp1); } fclose(fp); fclose(fp1); remove("s_xt"); rename("xt","s_xt"); printf("Data delet was succesful!"); printf("Anykey will return to "); getch();}main(){while(1){ clrscr(); /*清屏幕*/ gotoxy(1,1); /*移动光标*/ textcolor(YELLOW); /*设置文本显示颜色为黄色*/ textbackground(BLUE); /*设置背景颜色为蓝色*/ window(1,1,99,99); /* 制作显示菜单的窗口,大小根据菜单条数设计*/ clrscr(); printf("*************welcome to use student manage******************"); printf("*************************menu********************************"); printf("* ========================================================= * "); printf("* 1>shuru 2>xiugai * "); printf("* 3>shanchu 4>chazhao * "); printf("* 5>xianshi 6>exit * "); printf("* * "); printf("* --------------------------------------------------------- * "); printf(" Please input which you want(1-6):"); ch=getch(); switch(ch) { case 1:shuru();break; case 2:xiugai(); break; case 3:shanchu(); break; case 4:chazhao(); break; case 5:xianshi(); break; case 6:exit(0); default: continue; }}}