学生成绩管理系统(c)

1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 #include <unistd.h> Student 7 { 8char id[4]; 9char name[10]; 10int score; 11 }; 12 13 typedef struct User 14 { 15char userName[20]; 16char userPassword[10]; 17 }UserInfo; inputNameAndPassword(); 20 void logon(); 21 void creatDataBace(); 22 void selectServe(); 23 void checkAchievement(); 24 void addAchievement(); 25 void delectAchievement(); 26 void changeAchievement(); 27 void sortAchievement(); 28 void start();main(int argc, const char * argv[]) 31 { 32 start();system(); 35 36FILE *file;, ); 38struct Student aStudent; 39if (fread(&aStudent, sizeof(struct Student), 1, file)==0) { 40 creatDataBace(); 41 } 42 fclose(file); selectServe();; 48 } start() 51 { 52int land;);,&land); 55if (land==1) { 56 logon(); 57}else 58 { 59if (land==2) 60 inputNameAndPassword();{); 64 start(); 65 } 66 } 67 } logon() 70 { 71 UserInfo userInput;););,userInput.userName););,userInput.userPassword); 77FILE *fp;, ))==NULL) 79 {); 81exit(0); 82 } 83if ((fwrite(&userInput, sizeof(UserInfo), 1, fp))!=1) {); 85exit(0); 86 } 87 fclose(fp); 88 inputNameAndPassword(); 89 } inputNameAndPassword() 92 { 93UserInfo userInput,userBase[50]; 94int i=0,count=0,chance=0; 95 96FILE *fp;, ))==NULL) 98 {);100exit(0);101 }(fread(&userBase[i], sizeof(UserInfo), 1, fp)!=0)104i++;105count=i;106 fclose(fp););109while (1)110 {);,userInput.userName););,userInput.userPassword); (i=0; i<count; i++) {117if((strcmp(userInput.userName, userBase[i].userName)==0)&&(strcmp(userInput.userPassword, userBase[i].userPassword)==0))118return;119 }120if (chance!=3),3-chance);122chance++;123if (chance>=4) {);125exit(0);126 }127 }128 } selectServe()131 {132int serveNumber;);););,&serveNumber);137switch (serveNumber) {:139 checkAchievement();140break;:142 addAchievement();143break;:145 delectAchievement();146break;:148 changeAchievement();149break;:151 sortAchievement();152break;153default:154break;155 });157 } creatDataBace()160 {161FILE *fp;162struct Student student[100];163int flag=0;164int i=0;165int k=0;166int count=0;167int m=0;168char ch;((fp=fopen(, ))==NULL)171 {);173exit(0);174 }(i=0;fread(&student[i], sizeof(struct Student), 1, fp)!=0;i++);177count=i;178 fclose(fp););181i=0;182while (1) {);{,i+1);,student[i].id);(k=i-1; k>=0; k–) {190if(strcmp(student[i].id, student[k].id)==0)191 {);193flag=1;194break;195 }196 }(k=0; k<count; k++) {199if(strcmp(student[i].id, student[k].id)==0)200 {);202flag=1;203break;204 }205 }206}while(flag);{210flag=0;);,student[i].name);213}while (flag);{217flag=0;);,&student[i].score);220if (student[i].score>100||student[i].score<0) {221flag=1;222continue;223 }224}while (flag);225226i++;227m++;);229 getchar();,&ch);&&ch!=)232break;233 }((fp=fopen(, ))==NULL)237 {);239exit(0);240 }(i=0; i<m; i++) {243if (fwrite(&student[i], sizeof(struct Student), 1, fp)!=1));245 }246247 fclose(fp);248 } checkAchievement()251 {252struct Student student;253char id[4];254FILE *fp;););,id);259while (1)260 {,))==NULL)262 {);264 selectServe();265 }(fread(&student, sizeof(struct Student), 1, fp)!=0) {268if (strcmp(id,student.id)==0) {,student.id,student.name,student.score);270break;271 }272 }(strcmp(id,student.id)!=0),id););,id);)==)==0) {280 fclose(fp);281 selectServe();282 }283 fclose(fp);284 }285 } addAchievement()288 {289FILE *fp;290struct Student student[100];291int i=0;292int count=0;293char ch;((fp=fopen(, ))==NULL)296 {);298 selectServe();299 }(i=0;fread(&student[i], sizeof(struct Student), 1, fp)!=0;i++);302count=i;303 fclose(fp);((fp=fopen(, ))==NULL)306 {);308 selectServe();309 });312while (1)313 {314int flag;315do {316flag=0;);,student[count].id);319for (int k=0; k<count; k++) {320if(strcmp(student[count].id, student[k].id)==0)321 {);323flag=1;324break;325 }326 }327} while (flag););,student[count].name););,&student[count].score);332if (fwrite(&student[count], sizeof(struct Student), 1, fp)!=1) {);334 }););337 getchar();,&ch);&&ch!=) {340 fclose(fp);341 selectServe();342 }343count++;344 }345 } delectAchievement()348 {349char id[4];350char sure;351FILE *infile,*outfile;352struct Student students[100];353int i=0,flag=-1,count=0;printf();((infile=fopen(,))==NULL)359 {);361 selectServe();362 }(fread(&students[i], sizeof(struct Student), 1, infile)!=0) i++;365count=i;366 fclose(infile););,id);370while (1)371 {372for (i=0; i<count; i++) {373if (strcmp(id,students[i].id)==0) {374flag=i;375break;376 }377 }(flag==-1),id);{,id);384 getchar();,&sure);)387 {388for (i=flag; i<count-1; i++) {389students[i]=students[i+1];390 }391count–;,);394for (i=0; i<count; i++) {395if(fwrite(&students[i], sizeof(struct Student), 1, outfile)!=1)396 {);398 selectServe();399 }400 }401 fclose(outfile);402 });404 });,id);(strcmp(id,)==)==0) {unlink();rename( ,);selectServe();414 }415 } 416 } changeAchievement()419 {420FILE *fp;421char id[4],ch;422int score=0,count=0,flag=1;423int i=0;424struct Student students[100];((fp=fopen(,))==NULL)427 {);429 selectServe();430 }431while (fread(&students[i], sizeof(struct Student), 1, fp)!=0) i++;432count=i;433 fclose(fp););436while (1)437 {);,id);(i=0;i<count;i++) {443if (strcmp(id,students[i].id)==0) {,students[i].id,students[i].name,students[i].score);,students[i].name);,&score);447students[i].score=score;448flag=0;449break;450 }451 } (flag),id);((fp=fopen(,))==NULL)457 {);459 selectServe();460 }461for (i=0; i<count; i++) {462if(fwrite(&students[i], sizeof(struct Student), 1, fp)!=1)463 {);465 selectServe();466 }467 });470 getchar();,&ch);&&ch!=) {473 fclose(fp);474 selectServe();475 }476 }477 } sortAchievement()480 {481char ch;482FILE *fp;483struct Student students[100],temp;484int i=0,j=0,count=0;((fp=fopen(,))==NULL)487 {);489 selectServe();490 }(fread(&students[i], sizeof(struct Student), 1, fp)!=0) i++;493 fclose(fp);494count=i;);497for(i=0;i<count-1;i++)498for(j=0;j<count-1-i;j++)499 {500if (students[j].score<students[j+1].score) {501temp=students[j];502students[j]=students[j+1];503students[j+1]=temp;504 }505 }); (i=0; i<count; i++) {,students[i].id);509for (j=0; j<6-strlen(students[i].id); j++) 510printf(” “);,students[i].name);513for (j=0; j<10-strlen(students[i].name); j++) 514printf(” “);,students[i].score);517 });scanf(,&ch);522 selectServe();523524 },美国服务器,香港虚拟主机,香港服务器有本钱耍个性,离开睁眼闭眼看见的城市,逃离身边的纷纷扰扰,

学生成绩管理系统(c)

相关文章:

你感兴趣的文章:

标签云: