年初二 拿利事
我没有加文件保存,程序可以运行。
<!--StartFragment--># include<stdio.h> # include<conio.h> # include<string.h> struct student { char num[15]; char name[20]; char curcus[10][5]; char curcusname[10][10]; }; int m; int curricula; void clrscr(){ for(int i=0;i<38;i++) printf("\n"); } void mainmenu()//显示主界面 { clrscr(); printf("\n\n\n\n\n\n\n\n"); printf(" $*************************************$\n"); printf(" $ 0-------7 $\n"); printf(" $*************************************$\n"); printf(" $ 1-创建 $\n"); printf(" $ 2-显示 $\n"); printf(" $ 3-查询 $\n"); printf(" $ 4-修改 $\n"); printf(" $ 5-删除 $\n"); printf(" $ 6-插入 $\n"); printf(" $ 7-排序 $\n"); printf(" $ 0-退出 $\n"); printf(" $*************************************$\n"); printf(" "); } void creat(student stu[10])//创建 { int i,j; clrscr(); for(j=0;j<curricula;j++){ printf("请输入课程名称:\n"); gets(stu[0].curcusname[j]); } for(i=0;i<m;i++) { printf("\n"); printf("Please importation the %d record:\n",i); printf("num:"); do { gets(stu[i].num); } while(strcmp(stu[i].num,"") ==0);//保证输入的学好不为零 printf("name:"); gets(stu[i].name); for( j=0;j<curricula;j++) { printf("请输入第%d 门课程的成绩:",j); gets(stu[i].curcus[j]); } } } void display(student stu[10])//显示 { int i,j; clrscr(); // printf(str); printf(" num name"); for(j=0;j<curricula;j++) {printf("%8s",stu[0].curcusname[j]); } printf("\n"); for(i=0;i<m;i++) {printf("%13s%16s",stu[i].num,stu[i].name); for( j=0;j<curricula;j++) printf("%8s",stu[i].curcus[j]); printf("\n"); } } void qui_num(student stu[10])//按学号查找 { int i,j,flag=0; char nm[15]; printf("\n Please the importatiom regisration number:"); gets(nm); for(i=0;i<m;i++) if(strcmp(nm,stu[i].num)==0) { printf(" num name"); for(j=0;j<curricula;j++) {printf("%8s",stu[0].curcusname[j]); } printf("\n"); printf("%13s%16s",stu[i].num,stu[i].name); for( j=0;j<curricula;j++) printf("%8s",stu[i].curcus[j]); flag=1; } if(flag==0) printf("\n Check to have no this record! \n"); } void qui_name(student stu[10])//按姓名查找 { int i,j,flag=0; char nam[20]; printf("\n Please the importatiom name:");gets(nam); for(i=0;i<m;i++) if(strcmp(nam,stu[i].name)==0) { printf(" num name"); for(j=0;j<curricula;j++) {printf("%8s",stu[0].curcusname[j]); } printf("\n"); printf("%13s%16s",stu[i].num,stu[i].name); for( j=0;j<curricula;j++) printf("%8s",stu[i].curcus[j]); flag=1; } if(flag==0) printf("Check to have no this record! \n"); } void scarch(student stu[10])//查找 { char c; display(stu); printf("Press registration number search(n),press name search(x)?"); c=getche(); if(c=='n'||c=='N') qui_num(stu); else if(c=='x'||c=='X') qui_name(stu); else printf("\n Input the mistake word sign! \n"); } void modify(student stu[10])//修改 { int i,j; char nam[20]; clrscr(); display(stu); printf("Ask importation to want to modify the name of the record: \n"); gets(nam); for(i=0;i<m;i++) if (strcmp(nam,stu[i].name)==0) break; if(i==m) printf("Check to have no this record! \n"); else { printf("Please input the right registration number: \n"); do {gets(stu[i].num);} while(strcmp(stu[i].num,"")==0); printf("Newname:");gets(stu[i].name); for( j=0;j<curricula;j++) { printf("请输入第%d 门课程的成绩:",j); gets(stu[i].curcus[j]); } display(stu); } } void deletee(student stu[10])//删除 { int i,j,x; char c,nm[15],nam[20],cur[15]; clrscr(); display(stu); printf("Press the registration number deletion(h),still press name deletion(l),press curcuse deletion(c)?"); c=getche(); if (c=='h'||c=='H')//按学号删除 { printf("\n Ask importation to want to delete the registration number of the record: \n"); gets(nm); for (x=0;x<m;x++) if (strcmp(nm,stu[x].num)==0) break; if (x<m) { for (i=x;i<m-1;i++) { strcpy(stu[i].num,stu[i+1].num); strcpy(stu[i].name,stu[i+1].name); for(int j=0;j<curricula;j++) strcpy(stu[i].curcus[j],stu[i+1].curcus[j]); } m--; display(stu); } else printf("Check to have no this record! \n"); } else if (c=='l'||c=='L')//按姓名删除 { printf("\n Ask importation to want to delete the name the record: \n"); gets(nam); for (x=0;x<m;x++) if (strcmp(nam,stu[x].name)==0) break; if (x<m) { for (i=x;i<m-1;i++) { strcpy(stu[i].num,stu[i+1].num); strcpy(stu[i].name,stu[i+1].name); for(int j=0;j<curricula;j++) strcpy(stu[i].curcus[j],stu[i+1].curcus[j]); } m--; display(stu); } else printf("Check to have no this record! \n"); } else if (c=='c'||c=='C')//删除一门课程 { printf("\n Ask importation to want to delete the curcuse the record: \n"); gets(cur); for(x=0;x<curricula;x++) if(strcmp(cur,stu[0].curcusname[x])==0) break; if (x<curricula) { for(i=x;i<curricula;i++) { strcpy(stu[0].curcusname[i],stu[0].curcusname[i]); for (j=0;j<m;j++) strcpy(stu[j].curcus[i],stu[j].curcus[i+1]); } curricula--; display(stu); } else printf("Check to have no this record! \n"); } else printf("\n Input the mistake word sign! \n"); } void Increasestudent(student stu[10])//增加学生 { char c,tempnum[15],tempname[20]; clrscr(); display(stu); clrscr(); do { printf(" please the registration number of input the new record: \n"); do {gets(tempnum);} while(strcmp(tempnum,"")==0); printf(" please the surname number of input the new record: \n"); gets(tempname); for (int i=0;i<m;i++) if (strcmp(tempnum,stu[i].num)==0 || strcmp(tempname,stu[i].name)==0) { printf("Registration number or the name repetition want to inprt(YES\\NO)?"); c=getche(); putchar('\n'); break; } if(i==m) { strcpy(stu[i].num,tempnum); strcpy(stu[i].name,tempname); for(int j=0;j<curricula;j++){ printf("请输入第%d 门课程的成绩:",j); gets(stu[i].curcus[j]); } printf(" New result record:\n"); m++; display(stu); break; } }while(c=='y' || c=='Y'); } void Increasecurricual(student stu[10]){//增加课程 int i,j; char c; char course[10]; clrscr(); display(stu); clrscr(); do { printf("请输入课程名称:\n"); do {gets(course);} while(strcmp(course,"")==0); for (j=0;j<curricula;j++) if (strcmp(course,stu[0].curcusname[j])==0 ) { printf("Registration curcusename repetition want to inprt(YES\\NO)?"); c=getche(); putchar('\n'); break; } if(j==curricula) { strcpy(stu[0].curcusname[j],course); for( i=0;i<m;i++){ printf("请输入第%d 个学生的该门课程的成绩:",i); gets(stu[i].curcus[j]); } curricula++; printf(" New result record:\n"); display(stu); break; } }while(c=='y' || c=='Y'); } void Increase(student stu[10])//增加 { clrscr(); char c; printf("Press registration student increase(s),press curcuse search(c)?"); c=getche(); if(c=='s'||c=='S') Increasestudent(stu); else if(c=='c'||c=='C') Increasecurricual(stu); else printf("\n Input the mistake word sign! \n"); } void Arrange(student stu[10])//排序 { int i,j,l; char g,h,temp[10]; clrscr(); printf(" The result record that did not arrange: \n"); display(stu); printf("Press the registration numbdr alignment(n),still press name alignment(b)?"); g=getche(); if(g=='n' || g=='N') { printf("\n Press agreeable row(s),still negative row(f)?"); h=getche(); if(h=='s' || h=='S') { for(i=0;i<m-1;i++) { l=i; for(j=i;j<m;j++) if(strcmp(stu[l].num,stu[j].num) >0) l=j; strcpy(temp,stu[l].num); strcpy(stu[l].num,stu[i].num); strcpy(stu[i].num,temp); strcpy(temp,stu[l].name); strcpy(stu[l].name,stu[i].name); strcpy(stu[i].name,temp); for(int k=0;k<curricula;k++) { strcpy(temp,stu[l].curcus[k]); strcpy(stu[l].curcus[k],stu[i].curcus[k]); strcpy(stu[i].curcus[k],temp); } } printf("\n Arrange the result record of empress: \n"); display(stu); } else if(h=='f' || h=='F') { for(i=0;i<m-1;i++) { l=i; for(j=i;j<m;j++) if(strcmp(stu[l].num,stu[j].num) <0) l=j; strcpy(temp,stu[l].num); strcpy(stu[l].num,stu[i].num); strcpy(stu[i].num,temp); strcpy(temp,stu[l].name); strcpy(stu[l].name,stu[i].name); strcpy(stu[i].name,temp); for(int k=0;k<curricula;k++) { strcpy(temp,stu[l].curcus[k]); strcpy(stu[l].curcus[k],stu[i].curcus[k]); strcpy(stu[i].curcus[k],temp); } } printf("\n Arrange the result record of empress: \n"); display(stu); } else printf("\n Illegal character list! \n"); } else if (g=='b' || g=='B') { printf("\n Press agreeable row(s),still negative row(f)?"); h=getche(); if(h=='s' || h=='S') { for(i=0;i<m-1;i++) { l=i; for(j=i;j<m;j++) if(strcmp(stu[l].name,stu[j].name) >0) l=j; strcpy(temp,stu[l].num); strcpy(stu[l].num,stu[i].num); strcpy(stu[i].num,temp); strcpy(temp,stu[l].name); strcpy(stu[l].name,stu[i].name); strcpy(stu[i].name,temp); for(int k=0;k<curricula;k++) { strcpy(temp,stu[l].curcus[k]); strcpy(stu[l].curcus[k],stu[i].curcus[k]); strcpy(stu[i].curcus[k],temp); } } printf("\n Arrange the result record of empress: \n"); display(stu); } else if(h=='f' || h=='F') { for(i=0;i<m-1;i++) { l=i; for(j=i;j<m;j++) if(strcmp(stu[l].name,stu[j].name) <0) l=j; strcpy(temp,stu[l].num); strcpy(stu[l].num,stu[i].num); strcpy(stu[i].num,temp); strcpy(temp,stu[l].name); strcpy(stu[l].name,stu[i].name); strcpy(stu[i].name,temp); for(int k=0;k<curricula;k++) { strcpy(temp,stu[l].curcus[k]); strcpy(stu[l].curcus[k],stu[i].curcus[k]); strcpy(stu[i].curcus[k],temp); } } printf("\n Arrange the result record of empress: \n"); display(stu); } else printf("\n Illegal character list! \n"); } else printf("\n Illegal character list! \n"); } void main(){ student stu[10]; m=3; curricula=3; char choice,yes_no; do { clrscr(); mainmenu(); printf(" "); choice=getche(); switch(choice) { case'1':creat(stu);break; case'2':display(stu);break; case'3':scarch(stu);break; case'4':modify(stu);break; case'5':deletee(stu);break; case'6':Increase(stu);break; case'7':Arrange(stu);break; case'0':break; default:printf(" choice=%c!Illegal operation\n",choice); } if(choice=='0')break;//终止程序 printf("\n Need to be chosen afresh(Yes\\No)?\n"); do {yes_no=getch();} while (yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n'); } while(yes_no=='Y'||yes_no=='y'); }