c语言学生信息系统.zip
资源内容介绍
c语言学生信息系统.zip #include <stdio.h>#include <stdlib.h>#include <string.h>#define LEN sizeof(struct scorenode)#define DEBUGstruct scorenode{int number;char name[10];int xiaofei;struct scorenode *next;};typedef struct scorenode score;int n,k;/*n,k为全局变量,本程序中的函数均可*p3以使用它*/void menu();score *creat(void);score *load(score *head);score *search(score *head);score *del(score *head);score *add(score *head,score *stu);void print(score *head);save(score *p1);score *creat(void){score *head; score *p1,*p2,*p3,*max;int i,j; char t[10];n=0; p1=p2=p3=(score *)malloc(LEN); printf("please input student's information,input 0 exit!\n");repeat1: printf("please input student's number(number>0):"); scanf(" %d",&p1->number); while(p1->number<0) { getchar(); printf("error,please input number again:"); scanf("%d",&p1->number); } if(p1->number==0)goto end;else{p3=head;if(n>0){for(i=0;i<n;i++){if(p1->number!=p3->number)p3=p3->next;else{printf("number repeate,please input again!\n");goto repeat1; }}} } printf("please input student's name:"); scanf("%s",&p1->name); printf("please input student's consume money:"); scanf("%d",&p1->xiaofei); while(p1->number!=0) { n=n+1; if(n==1) head=p1; else p2->next=p1; p2=p1; p1=(score *)malloc(LEN); printf("please input student's information,input 0 exit!\n");repeat2:printf("please input student's number(number>0):"); scanf("%d",&p1->number); while(p1->number<0) {getchar(); printf("error,please input number again:"); scanf("%d",&p1->number);} if(p1->number==0) goto end; else { p3=head; if(n>0) {for(i=0;i<n;i++) {if(p1->number!=p3->number) p3=p3->next; else {printf("number repeate,please input again!\n"); goto repeat2; } } } } printf("please input student's name:"); scanf("%s",&p1->name); printf("please input student's consume money:"); scanf("%d",&p1->xiaofei);}end: p1=head; p3=p1; for(i=1;i<n;i++) { for(j=i+1;j<=n;j++) { max=p1; p1=p1->next; if(max->number>p1->number) { k=max->number; max->number=p1->number; p1->number=k; strcpy(t,max->name); strcpy(max->name,p1->name); strcpy(p1->name,t); } } max=head;p1=head; }p2->next=NULL; printf("input student's num:%d ge!\n",n); getch(); return(head);}score *load(score *head){score *p1,*p2; int m=0; char filepn[10];FILE *fp;printf("please input file's postion and its name:");scanf("%s",filepn);if((fp=fopen(filepn,"r+"))==NULL){printf("can't open this file!\n");getch();return 0;}else{p1=(score *)malloc(LEN); fscanf(fp,"%d%s%d\n",&p1->number,p1->name,&p1->xiaofei);printf("|%d\t|%s\t|%d\t\n",p1->number,p1->name,p1->xiaofei);head=NULL;do{n=n+1;if(n==1)head=p1;elsep2->next=p1;p2=p1;p1=(score *)malloc(LEN); fscanf(fp,"%d%s%d\n",&p1->number,p1->name,&p1->xiaofei);printf("|%d\t|%s\t|%d\t\n",p1->number,p1->name,p1->xiaofei);}while(!feof(fp));p2->next=p1;p1->next=NULL;n=n+1;}printf("-----------------------------------------\n");getch();fclose(fp);return (head);}score *search(score *head){int number;score *p1,*p2;printf("input the student's number of searching:");scanf("%d",&number);getchar();while(number!=0){if(head==NULL){printf("\n nobody information!\n");return(head);}printf("-----------------------------------------\n");printf("|number\t|name\t|consume\t \n");printf("-----------------------------------------\n");p1=head;while(number!=p1->number&&p1->next!=NULL){p2=p1;p1=p1->next;} if(number==p1->number){ printf("|%d\t|%s\t|%d\t\n",p1->number,p1->name,p1->xiaofei); printf("-----------------------------------------\n");} elseprintf("%dthis student not exist!\n",number);printf("input the student's number of searching:");scanf("%d",&number);getchar();}printf("already exit!\n");getchar();return(head);}score *del(score *head){score *p1,*p2;int number;printf("input the student's number of deleting(input 0 exit):");scanf("%d",&number);getchar();while(number!=0){if(head==NULL){printf("\nnobody information!\n");return(head);}p1=head;while(number!=p1->number&&p1->next!=NULL) {p2=p1;p1=p1->next;} if(number==p1->number) {if(p1==head)head=p1->next; elsep2->next=p1->next; printf("delete number:%d\n",number);n=n-1;}elseprintf("%d student not exist!\n",number); printf("input the student's number of deleting:");scanf("%d",&number);getchar();}#ifdef DEBUG printf("already exit\n");#endif printf("now how many students:%d ge!\n",n); getch(); return(head);}score *add(score *head,score *stu){score *p0,*p1,*p2,*p3,*max; int i,j; char t[10];p3=stu=(score *)malloc(LEN);printf("\ninput the student's information of adding!");repeat4: printf("please input the student's number(number>0):");scanf("%d",&stu->number); while(stu->number<0){getchar();printf("error,please input number again:");scanf("%d"