[置顶] C语言项目--教师信息/学生成绩管理系统
这个系统实现两个功能,分别是管理教师的信息和学生的成绩,用户可以选择切换实现相应的功能。话不多说了,现在看下程序的实现截图:
这里给出程序代码下载地址:http://download.csdn.net/detail/dlutbrucezhang/5191828
下面贴出部分代码:
void add_tea(Teacher tea[]) { int i=0,j,num; char str[5]; if(numtea!=0) { printf("cover the current record?(y/n)\n"); gets(str); if(str[0]=='Y'||str[0]=='y') i=0; else i=numtea; } printf("Please input the number of you add the teachers:"); scanf("%d",&num); if(i==0) numtea=num; else numtea+=num; if(numtea>lens) { lens+=10; tea=(Teacher *)realloc(tea,lens*SIZE); } printf("Please input the teacher's info:\n"); for(;i<numtea;i++) { getchar(); printf("please input the teacher's NO.:"); gets(tea[i].number); printf("please input the teacher's name:"); gets(tea[i].name); printf("please input the teacher's sex(man/woman 0/1):"); gets(tea[i].sex); if(tea[i].sex[0]=='0') strcpy(tea[i].sex,"man"); else strcpy(tea[i].sex,"woman"); printf("please input the teacher's address:"); gets(tea[i].addr); printf("the teacher is married(No/Yes 0/1):"); gets(tea[i].married); if(tea[i].sex[0]=='0') strcpy(tea[i].sex,"No"); else strcpy(tea[i].sex,"Yes"); } display_tea(tea,0,numtea-1); getchar(); } void display_tea(Teacher tea[],int n1,int n2) { int i; char str[2]; if(numtea==0){ printf("There is Nothing!\n"); printf("Do you want to open some file to find the record?(Y/N)\n"); gets(str); if (str[0]=='Y'||str[0]=='y') { openfileTXT(tea); } else { return; } } else { for(i=n1;i<=n2;i++) printf("number:%s\tname:%s\t\tsex:%s\t\taddr:%s\t\tmarried:%s\t",tea[i].number,tea[i].name,tea[i].sex,tea[i].addr,tea[i].married); } } void adjust(Teacher tea[]) { char str[5]; int i=-1,j; if(numtea==0) { printf("there is nothing !!!\n"); return; } while(i<0) { i=find_tea(tea); if(i>=0) { printf("Delete it?(y/n)"); gets(str); if(str[0]=='y'||str[0]=='Y') { delete_tea(tea,i); /*count(stud); */ } else { printf("Adjust it?(y/n)"); gets(str); if(str[0]=='y'||str[0]=='Y') { printf("Please input something you want:\n"); printf("please input the teacher's NO.:"); gets(tea[i].number); printf("please input the teacher's name:"); gets(tea[i].name); printf("please input the teacher's sex(man/woman 0/1):"); gets(tea[i].sex); if(tea[i].sex[0]=='0') strcpy(tea[i].sex,"man"); else strcpy(tea[i].sex,"woman"); printf("please input the teacher's address:"); gets(tea[i].addr); printf("the teacher is married(No/Yes 0/1):"); gets(tea[i].married); if(tea[i].sex[0]=='0') strcpy(tea[i].sex,"No"); else strcpy(tea[i].sex,"Yes"); } /*count(stud); */ } display_tea(tea,0,numtea-1); } printf("Again to Adjust it ?(y/n)\n"); gets(str); if(str[0]=='y'||str[0]=='Y') i=-1; else i=1; } } int find_tea(Teacher tea[]) { char str[10]; int i; if(numtea==0) { printf("There is nothing\n"); return -1; } else { printf("what do you want your fashion ?\n1.number\t2.name\t3.addr\n"); gets(str); if(str[0]=='1') { printf("please input the teacher's number:"); gets(str); for(i=0;i<=numtea;i++) if(strcmp(str,tea[i].number)==0) { display_tea(tea,i,i); break; } else continue; } else if(str[0]=='2') { printf("please input the teacher's name:"); gets(str); for(i=0;i<=numtea;i++) if(strcmp(str,tea[i].name)==0) { display_tea(tea,i,i); break; } else continue; } else if(str[0]=='3') { printf("please input the teacher's address:"); gets(str); for(i=0;i<=numtea;i++) if(strcmp(str,tea[i].addr)==0) { display_tea(tea,i,i); break; } else continue; } if(i>numtea) { printf("Nothing has find\n"); return -1; } return i; } } void delete_tea(Teacher tea[],int i) { int j; while(i>=0) { for(j=i;j<numtea;j++) tea[j]=tea[j+1]; numtea--; printf("Delete Success!\n"); } } int writetoTXT(Teacher tea[]) { int i=0,j; FILE *fp; char filename[20]; printf("Please input the file's name:"); gets(filename); fp=fopen(filename,"w"); fprintf(fp,"%d\n",numtea); while(i<numtea) { fprintf(fp,"%s %s %s %s %s",tea[i].number,tea[i].name,tea[i].sex,tea[i].addr,tea[i].married); i++; } fclose(fp); printf("Save success!!!\n"); display_tea(tea,0,numtea-1); numtea=0; return 0; } int openfileTXT(Teacher tea[]) { int i=0,j; FILE *fp; char filename[20],str[2]; if(numtea!=0) { printf("There has some records,Do you want to save them?(y/n)"); gets(str); if(str[0]=='y'||str[0]=='Y') writetoTXT(tea); } printf("Please input the file name:"); gets(filename); numtea=0; if((fp=fopen(filename,"rb+"))==NULL) { printf("Sorry ,can't open the file\n"); return(-1); } fscanf(fp,"%d",&numtea); fgetc(fp); while(i<numtea) { fscanf(fp,"%s",&tea[i].number); fscanf(fp,"%s",&tea[i].name); fscanf(fp,"%s",&tea[i].sex); fscanf(fp,"%s",&tea[i].addr); fscanf(fp,"%s",&tea[i].married); i++; } fclose(fp); printf("Read the file success\n"); printf("Display the record ?(y/n)"); gets(str); if(str[0]=='y'||str[0]=='Y') display_tea(tea,0,numtea-1); return(0); } void displayTheSystemInfo() { printf("\t\t制作人员: \n\n"); printf("\t\t张虎(BruceZhang)\n"); printf("\n\n"); }