一.题目:这是一个学生程序管理系统
二,要求:
1.能建立新数据文件,存放学生信息及成绩.
2.能追加新记录.
3.能修改已有记录.
4.能删除错误记录.
5.能查询部分记录.
6.能排序部分记录.
7.能用菜单方法操作.
以下是友人所做,我看不懂,请高手帮忙修一下.
# define m 5 # include<stdio.h> # include<conio.h> # include<string.h> void main menu() { clrscr(); printf("\n\n\n\n\n\n\n\n"); printf(" $*************************************$\n"); printf(" $ 0-------7 $\n"); printf(" $*************************************$\n"); printf(" $ 1-Establish the resrlt watch $\n"); printf(" $ 2-Show the resrlt watch $\n"); printf(" $ 3-Scarch the resrlt record $\n"); printf(" $ 4-Modify the result record $\n"); printf(" $ 5-Delete the result record $\n"); printf(" $ 6-Increase the new result record $\n"); printf(" $ 7-Arrange the result record $\n"); printf(" $ 0-Exit $\n"); printf(" $*************************************$\n"); } void creat(char num[m][20],char name[m][20],char mht[m][20],char els[m][20],char law[m][20]) { int i; clrscr(); for(i=0;i<m;i++) { printf("\n"); printf("Please importation the %d record:\n",i++); printf("num:"); do { gets(num[i]); } while(strcmp(num[i],"") ==0); printf("name:"); gets(name[i]); printf("mht:"); gets(mht[i]); printf("els:"); gets(els[i]); printf("law:"); gets(law[i]); } } void display(char num[m][20],char name[m][20],char mht[m][20],char els[m][20],char law[m][20]) { int i; clrscr(); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } void qui_num(char num[m][15],char name[m][20],char mht[m][5],char els[m][5],char law[m][5]) { int i,flag=0; char nm[15]; printf("\n Please the importatiom regisration number:");gets(nm); for(i=0;i<m;i++) if(strcmp(nm,num[i])==0) { printf(" num | name | mht | els | law |\n"); printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); flag=1; } if(flag==0) printf("\n Check to have no this record! \n"); } void qui_name(char num[m][15],char name[m][20],char mht[m][5],char els[m][5],char law[m][5]) { int i,flag=0; char nam[20]; printf("\n Please the importatiom name:");gets(nam); for(i=0;i<m;i++) if(strcmp(nam,num[i])==0) { printf(" num | name | mht | els | law |\n"); printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); flag=1; } if(flag==0) printf("Check to have no this record! \n"); } void scarch(char num[m][15],char name[m][20],char mht[m][5],char els[m][5],char law[m][5]) { char c; display(num,name,mht,els,law); printf("Press registration number search(n),press name search(x)?"); c=getche(); if(c=='n'||c=='N') qui_num(num,name,mht,els,law); else if(c=='x'||c=='X') qui_name(num,name,mht,els,law); else printf("\n Input the mistake word sign! \n"); } void modify(char num[m][15],char name[m][20],char mht[m][5],char els[m][5],char law[m][5]) { int i; char nam[20]; clrscr(); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]);
printf("Ask importation to want to modify the name of the record: \n"); gets(nam); for(i=0;i<m;i++) if (strcmp(nam,name[i])==0) break; if(i==m) printf("Check to have no this record! \n"); else { printf("Please input the right registration number: \n"); do {gets(num[i]);} while(strcmp(num[i],"")==0); printf("Newname:");gets(name[i]); printf("Newmht:"); gets(mht[i]); printf("Newels:");gets(els[i]); printf("Newlaw:");gets(law[i]); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } } void delete(char num[m][15],char name[m][20],char mht[m][5],char els[m][5],char law[m][5]) { int i,x; char c,nm[15],nam[20];
clrscr();
printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); printf("Press the registration number deletion(h),still press name deletion(l)?"); 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,num[x])==0) break; if (x<m) { for (i=x;i<m-1;i++) { strcpy(num[i],num[i+1]); strcpy(name[i],name[i+1]); strcpy(mht[i],mht[i+1]); strcpy(els[i],els[i+1]); strcpy(law[i],law[i+1]); } printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } 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(nm,num[x])==0) break; if (x<m) { for (i=x;i<m-1;i++) { strcpy(num[i],num[i+1]); strcpy(name[i],name[i+1]); strcpy(mht[i],mht[i+1]); strcpy(els[i],els[i+1]); strcpy(law[i],law[i+1]); } printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } else printf("Check to have no this record! \n"); } else printf("\n Input the mistake word sign! \n"); } void Increase(char num[10][15],char name[10][20],char mht[10][5],char els[10][5],char law[10][5]) { int i=0,k; char c,tempnum[15],tempname[20],tempmht[5],tempels[5],templaw[5];
clrscr();
printf(" num | name | mht | els | law |\n"); while(strcmp(num[i],"")!=0) { printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); i++; } k=i; 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); printf(" please the mht number of input the new record: \n");gets(tempmht); printf(" please the els number of input the new record: \n");gets(tempels); printf(" please the law number of input the new record: \n");gets(templaw); for (i=0;i<k;i++) if (strcmp(tempnum,num[i])==0 || strcmp(tempname,name[i])==0) { printf("Registration number or the name repetition want to inprt(YES\\NO)?"); c=getche(); putchar('\n'); break; } if(i==k) { strcpy(num[i],tempnum); strcpy(name[i],tempname); strcpy(mht[i],tempmht); strcpy(els[i],tempels); strcpy(law[i],templaw); printf(" New result record:\n"); printf(" num | name | mht | els | law |\n"); for(i=0;i<k+1;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); break; } }while(c=='y' || c=='Y'); } void Arrange(char num[m][15],char name[m][20],char mht[m][5],char els[m][5],char law[m][5]) { int i,j,l; char g,h,temp[10]; clrscr(); printf(" The result record that did not arrange: \n"); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); 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(num[l],num[j]) >0) l=j; strcpy(temp,num[l]); strcpy(num[l],num[i]); strcpy(num[i],temp); strcpy(temp,name[l]); strcpy(name[l],name[i]); strcpy(name[i],temp); strcpy(temp,mht[l]); strcpy(mht[l],mht[i]); strcpy(mht[i],temp); strcpy(temp,els[l]); strcpy(els[l],els[i]); strcpy(els[i],temp); strcpy(temp,law[l]); strcpy(law[l],law[i]); strcpy(law[i],temp); } printf("\n Arrange the result record of empress: \n"); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } else if(h=='f' || h=='F') { for (i=0;i<m-1;i++) { l=i; for(j=i;j<m;j++) if(strcmp(num[l],num[j]) <0) l=j; strcpy(temp,num[l]); strcpy(num[l],num[i]); strcpy(num[i],temp); strcpy(temp,name[l]); strcpy(name[l],name[i]); strcpy(name[i],temp); strcpy(temp,mht[l]); strcpy(mht[l],mht[i]); strcpy(mht[i],temp); strcpy(temp,els[l]); strcpy(els[l],els[i]); strcpy(els[i],temp); strcpy(temp,law[l]); strcpy(law[l],law[i]); strcpy(law[i],temp); } printf("\n Arrange the result record of empress: \n"); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } 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(num[l],num[j]) >0) l=j; strcpy(temp,num[l]); strcpy(num[l],num[i]); strcpy(num[i],temp); strcpy(temp,name[l]); strcpy(name[l],name[i]); strcpy(name[i],temp); strcpy(temp,mht[l]); strcpy(mht[l],mht[i]); strcpy(mht[i],temp); strcpy(temp,els[l]); strcpy(els[l],els[i]); strcpy(els[i],temp); strcpy(temp,law[l]); strcpy(law[l],law[i]); strcpy(law[i],temp); } printf("\n Arrange the result record of empress: \n"); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } else if(h=='f' || h=='F') { for (i=0;i<m-1;i++) { l=i; for(j=i;j<m;j++) if(strcmp(num[l],num[j]) <0) l=j; strcpy(temp,num[l]); strcpy(num[l],num[i]); strcpy(num[i],temp); strcpy(temp,name[l]); strcpy(name[l],name[i]); strcpy(name[i],temp); strcpy(temp,mht[l]); strcpy(mht[l],mht[i]); strcpy(mht[i],temp); strcpy(temp,els[l]); strcpy(els[l],els[i]); strcpy(els[i],temp); strcpy(temp,law[l]); strcpy(law[l],law[i]); strcpy(law[i],temp); } printf("\n Arrange the result record of empress: \n"); printf(" num | name | mht | els | law |\n"); for(i=0;i<m;i++) printf("%13s%16s%7s%7s%7s\n",num[i],name[i],mht[i],els[i],law[i]); } else printf("\n Illegal character list! \n"); } else printf("\n Illegal character list! \n"); } main() { char choice,yes_no,num[m][15],name[m][20],mht[m][5],els[m][5],law[m][5]; do { clrscr(); mainmenu(); printf(" "); choice=getche(); switch(choice) { case'1':creat(num,name,mht,els,law);break; case'2':display(num,name,mht,els,law);break; case'3':scarch(num,name,mht,els,law);break; case'4':modify(num,name,mht,els,law);break; case'5':delete(num,name,mht,els,law);break; case'6':Increase(num,name,mht,els,law);break; case'7':Arrange(num,name,mht,els,law);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'); }