#include#include#includevoidfrist_print(){printf("\t\t********************************\n\n");//欢迎信息printf("\t\t\t欢迎进入学生成绩系统\n");}voidmenu(){printf("\n\t\t********************************\n");//管理菜单printf("\t\t==\t1.录入学生成绩\n\t\t+\n");printf("\t\t==\t2.显示学生成绩\n\t\t+\n");printf("\t\t==\t3.查询学生成绩\n\t\t+\n");printf("\t\t==\t4.添加学生成绩\n\t\t+\n");printf("\t\t==\t5.修改学生成绩\n\t\t+\n");printf("\t\t==\t6.删除学生成绩\n\t\t+\n");printf("\t\t==\t7.清空页面\n\t\t+\n");printf("\t\t==\t8.退出系统\n");printf("\t\t********************************\n");printf("pleasechoise1--8:\t");putchar(10);}structMM//结构体定义变量{charnum[20];charname[10];floatpay;intmany;}mm;voidscanf_1()//第一次输入信息并保存在文件中{charch;FILE*fp;if((fp=fopen("dd.dat","wb+"))==NULL){printf("cannotopenfile\n");exit(0);}do{printf("请输入成绩的--编号:\t");getchar();gets(mm.num);printf("姓名:\t");gets(mm.name);printf("成绩:\t");scanf("%f",&mm.pay);printf("学号:\t");scanf("%d",&mm.many);if(fwrite(&mm,sizeof(structMM),1,fp)!=1){printf("filewriteerror\n");exit(0);}printf("是否继续输入yorn?\t");getchar();ch=getchar();}while(ch=='y'||ch=='Y');fclose(fp);}voidfind()//查询成绩的信息{inta,b=0;charch[20];FILE*fp;if((fp=fopen("dd.dat","rb"))==NULL){printf("cannotopenfile\n");exit(0);}printf("请输入要查询的成绩的方式\n\t1.编号2.姓名:\n\t请选择1or2\t");scanf("%d",&a);if(a==1){getchar();printf("请输入成绩的编号:\t");gets(ch);while(fread(&mm,sizeof(structMM),1,fp)==1)if(strcmp(mm.num,ch)==0){b++;printf("编号\t姓名\t价格\t\t学号\n");printf("%s\t%s\t%.3f\t\t%d\n",mm.num,mm.name,mm.pay,mm.many);}if(b==0)printf("对不起!没有找到相关信息:\n");}elseif(a==2){printf("请输入成绩的姓名:\t");getchar();gets(ch);while(fread(&mm,sizeof(structMM),1,fp)==1)if(strcmp(mm.name,ch)==0){b++;printf("编号\t姓名\t价格\t\t学号\n");printf("%s\t%s\t%.3f\t\t%d\n",mm.num,mm.name,mm.pay,mm.many);}if(b==0)printf("inputerror!\n");}fclose(fp);}voidscanf_2()//第二次输入信息并保存在文件中{charch;FILE*fp;if((fp=fopen("dd.dat","ab"))==NULL){printf("cannotopenfile\n");exit(0);}do{printf("请输入要添加成绩的--编号:\t");getchar();gets(mm.num);printf("姓名:\t");gets(mm.name);printf("价格:\t");scanf("%f",&mm.pay);printf("学号:\t");scanf("%d",&mm.many);if(fwrite(&mm,sizeof(structMM),1,fp)!=1){printf("filewriteerror\n");exit(0);}printf("是否继续输入yorn?\t");getchar();ch=getchar();}while(ch=='y'||ch=='Y');fclose(fp);}voidprint()//输出文档中的信息{FILE*fp;if((fp=fopen("dd.dat","rb"))==NULL){printf("cannotopenfile\n");return;}printf("编号\t姓名\t价格\t\t学号\n");while(fread(&mm,sizeof(structMM),1,fp)==1)printf("%s\t%s\t%.3f\t\t%d\n",mm.num,mm.name,mm.pay,mm.many);fclose(fp);}voidchange(){//修改信息的函数,定义另一个文件,把要修改的信息放到该文件中structXX//然后把其余的信息复制到该文件中;并把该文件从新命名为原来的名{//把原来的文件移除;charnum[20];charname[10];floatpay;intmany;}xx;FILE*fp2;inta,b=0,c=0,n=0;charch[20],ck;FILE*fp;do{if((fp=fopen("dd.dat","rb"))==NULL){printf("cannotopenfile\n");exit(0);}if((fp2=fopen("temp.dat","wb"))==NULL){printf("cannotopenfile\n");exit(0);}printf("请输入要修改成绩的编号:\t");scanf("%s",ch);n++;while(fread(&mm,sizeof(structMM),1,fp)==1){if((strcmp(mm.num,ch)==0)){b++;//b的值如果一直没有改变说明,没有找到相关的信息;printf("编号\t姓名\t价格\t\t学号\n");printf("%s\t%s\t%.3f\t\t%d\n",mm.num,mm.name,mm.pay,mm.many);getchar();printf("请输入成绩的新编号:\t");gets(xx.num);printf("请输入成绩的新姓名:\t");gets(xx.name);printf("请输入成绩的新价格:\t");scanf("%f",&xx.pay);printf("请输入成绩新学号:\t");scanf("%d",&xx.many);getchar();fwrite(&xx,sizeof(structXX),1,fp2);}if(strcmp(mm.num,ch)!=0)fwrite(&mm,sizeof(structMM),1,fp2);}if(b==0){printf("\t没有找到相关信息!\n");getchar();}rewind(fp);//如果要继续修改的话,要把标记返回到文件的开头;printf("是否继续修改?enter'y'or'n'\t");ck=getchar();fclose(fp);fclose(fp2);remove("dd.dat");rename("temp.dat","dd.dat");}while(ck=='y'||ck=='Y');if(b!=0)//如果没有找到相关信息就不能输出printf("\t修改成功:\n");}voiddel(){//删除函数和修改很相似FILE*fp2;inta,b=0,c=0,n=0;charch[20],ck;FILE*fp;do{if((fp=fopen("dd.dat","rb"))==NULL){printf("cannotopenfile\n");exit(0);}if((fp2=fopen("temp.dat","wb"))==NULL){printf("cannotopenfile\n");exit(0);}printf("请输入要删除成绩的编号:\t");scanf("%s",ch);n++;while(fread(&mm,sizeof(structMM),1,fp)==1){if((strcmp(mm.num,ch)==0)){b++;//b的值如果一直没有改变说明,没有找到相关的信息;printf("编号\t姓名\t价格\t\t学号\n");printf("%s\t%s\t%.3f\t\t%d\n",mm.num,mm.name,mm.pay,mm.many);}elseif(strcmp(mm.num,ch)!=0)fwrite(&mm,sizeof(structMM),1,fp2);}if(b==0){printf("\t没有找到相关信息!\n");getchar();}rewind(fp);getchar();getchar();printf("删除成功!");getchar();//如果要继续修改的话,要把标记返回到文件的开头;printf("是否继续删除?enter'y'or'n'\t");ck=getchar();fclose(fp);fclose(fp2);remove("dd.dat");rename("temp.dat","dd.dat");}while(ck=='y'||ck=='Y');if(b!=0)//如果没有找到相关信息就不能输出printf("\t保存成功:\n");}voidmyexit(){inta;charch;printf("\t是否确定退出?请选择yorn:");getchar();ch=getchar();if(ch=='y'||ch=='Y')exit(0);elsemenu();}intmain(){inta;frist_print();menu();while(1){scanf("%d",&a);if(a==1)scanf_1();elseif(a==2)print();elseif(a==3)find();elseif(a==4)scanf_2();elseif(a==5)change();elseif(a==6)del();elseif(a==7)system("cls");elseif(a==8)myexit();elseprintf("输入错误!!!请重新输入:\t");printf("\t按任意键继续!\n");getch();menu();}getch();}一个成绩管理系统,注释不是太多,写的不太好,能运行,符合你初级水平。满意请采纳。
你好!看着有点复杂,程序什么时间要,可以尝试完成