diff --git a/有bug的课设2.0.c b/有bug的课设2.0.c new file mode 100644 index 0000000..5e61f64 --- /dev/null +++ b/有bug的课设2.0.c @@ -0,0 +1,492 @@ +#include +#include +#include +#include +void prin1(); +void choose(); +typedef struct subjects //¶¨Òå¿Î³ÌÐÅÏ¢½á¹¹Ìå +{ + int num; //¿Î³Ì±àºÅ + char name[20]; //¿Î³ÌÃû³Æ + char kind[10];//¿Î³ÌÐÔÖÊ + int stime;//×Üѧʱ + int ttime;//ÊÚ¿Îѧʱ + int etime;//ʵÑé»òÉÏ»úѧʱ + int score;//ѧ·Ö + int term;//¿ª¿ÎѧÆÚ + struct subjects *next; + } SUB; + SUB *head=NULL; + //ÏÂÃ涨ÒåÁ´±íÄ£¿é + SUB *create_form() + { + SUB *head,*tail,*p;//¶¨ÒåÍ·½Úµã£¬Î²½Úµã£¬Öмä½Úµã¡£ + int num,stime,ttime; + int etime,score,term; + char name[20],kind[10]; + int size=sizeof(SUB); + head=tail=NULL; + printf("ÊäÈëÑ¡Ð޿γÌÐÅÏ¢:\n"); + scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term); + while(num!=0) + { + p=(SUB *)malloc(size); + p->num=num; + strcpy(p->name,name); + strcpy(p->kind,kind); + p->stime=stime; + p->ttime=ttime; + p->etime=etime; + p->score=score; + p->term=term; + if(head==NULL) + head=p; + else + tail->next=p; + tail=p; + scanf("%d%s%s%d%d%d%d%d",&num,name,kind,&stime,&ttime,&etime,&score,&term); + } + tail->next=NULL; + return head; + } + //±£´æÎļþÄ£¿é + void savefile() //±£´æÎļþ + { + SUB *p; + FILE *fp;fp=fopen("2.txt","w"); +if(fp==NULL)exit(0); +printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉϼ¶Ñ§Ê± ѧ·Ö ¿ª¿ÎѧÆÚ\n"); +for(p=head;p;p=p->next) +fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term); +fclose(fp); +printf("´´½¨ºóÐÅÏ¢ÒÑ·ÅÈë'2.txt'ÎļþÖÐ\n"); +system("pause");} +void savefile1() +{ + SUB *p; + FILE *fp;fp=fopen("3.txt","w"); +if(fp==NULL)exit(0); +for(p=head;p;p=p->next) +fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",p->num,p->name,p->kind,p->stime,p->ttime,p->etime,p->score,p->term); +fclose(fp); +printf("´´½¨ºóÐÅÏ¢ÒÑ·ÅÈë'3.txt'ÎļþÖÐ\n"); +system("pause"); + + +} + //¶ÁÈ¡ÎļþÄ£¿é + void readfile()//ÔĶÁÎļþ + { + void *myInsert(SUB*); + SUB *newSub;//ÐÂ¿Î³Ì + int num,stime,ttime,etime; + int score,term; + char c,name[20],kind[10],fname[20]; + FILE *fp; + fp=fopen("2.txt","r"); + while(!feof(fp)) + { + newSub=(SUB*)malloc(sizeof(SUB)); + fscanf(fp,"%d%s%s%d%d%d%d%d\n",&newSub->num,newSub->name,newSub->kind,&newSub->stime,&newSub->ttime,&newSub->etime,&newSub->score,&newSub->term); + myInsert(newSub); + } + fclose(fp); + } + void read() + { + void *myInsert(SUB*); + SUB *newSub;//ÐÂ¿Î³Ì + int num,stime,ttime,etime; + int score,term; + char c,name[20],kind[10],fname[20]; + FILE *fp; + fp=fopen("3.txt","r"); + while(!feof(fp)) + { + newSub=(SUB*)malloc(sizeof(SUB)); + fscanf(fp,"%d%s%s%d%d%d%d%d\n",&newSub->num,newSub->name,newSub->kind,&newSub->stime,&newSub->ttime,&newSub->etime,&newSub->score,&newSub->term); + myInsert(newSub); + } + fclose(fp); + } + //ÏÂÃ涨Òåä¯ÀÀÄ£¿é + void prin() + { + SUB *ptr; + head=NULL; + readfile(); + if(head==NULL) + { + printf("\n\n\t**********NO RECORDS!**********\n"); + return; + } + printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉϼ¶Ñ§Ê± ѧ·Ö ¿ª¿ÎѧÆÚ\n"); + for(ptr=head;ptr;ptr=ptr->next) + { + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); + + } + system("pause"); + } + //ÏÂÃ涨Òåä¯ÀÀÒÑÑ¡Ð޿γÌÄ£¿é + void prin1() + { + SUB *ptr; + head=NULL; + read(); + if(head==NULL) + { + printf("\n\n\t**********NO RECORDS!**********\n"); + return; + } + printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉϼ¶Ñ§Ê± ѧ·Ö ¿ª¿ÎѧÆÚ\n"); + for(ptr=head;ptr;ptr=ptr->next) + { + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); + + } + system("pause"); +} + + + //²åÈëÁ´±íÄ£¿é + void *myInsert(SUB *subj)//Á´±í²åÈë²Ù×÷ + { + SUB *ptr,*ptr2; + ptr=subj; + if(head==NULL) + { + head=ptr; + head->next=NULL; + } + else + { + for(ptr2=head;ptr2;ptr2=ptr2->next) + if(ptr2->next==NULL) + { + ptr2->next=subj; + subj->next=NULL; + break; + } + } + return head; + } + + //Ìí¼ÓÄ£¿é + void *insert() + { + SUB *ptr,*subj; + int size=sizeof(SUB); + char ch,ch1; + while(ch!='0') + { + subj=(SUB *)malloc(size); + ptr=subj; + printf("ÇëÊäÈëÒª²åÈëµÄ¿Î³ÌÐÅÏ¢:\n"); + printf("\n\t\t ÇëÊäÈë¿Î³Ì±àºÅ:"); + scanf("%d",&subj->num); + printf("\n\t\t ÇëÊäÈë¿Î³ÌÃû³Æ:"); + scanf("%s",&subj->name); + printf("\n\t\t ÇëÊäÈë¿Î³ÌÐÔÖÊ:"); + scanf("%s",&subj->kind); + printf("\n\t\t ÇëÊäÈë×Üѧʱ:"); + scanf("%d",&subj->stime); + printf("\n\t\t ÇëÊäÈëÊÚ¿Îѧʱ:"); + scanf("%d",&subj->ttime); + printf("\n\t\t ÇëÊäÈëʵ¼ù»òÉÏ»úѧʱ:"); + scanf("%d",&subj->etime); + printf("\n\t\t ÇëÊäÈëѧ·Ö:"); + scanf("%d",&subj->score); + printf("\n\t\t ÇëÊäÈ뿪¿ÎѧÆÚ:"); + scanf("%d",&subj->term); + myInsert(subj); + printf("\nÌí¼ÓÍê±Ï£¬ÐÂÐÅÏ¢´æÈëÎļþ¼Ð\n"); + printf("\n\n ¼ÌÐø²åÈëÇë°´»Ø³µ\n"); + printf("\n½áÊøÌí¼ÓÇë°´ 0:[ ]\b\b"); + ch1=getchar(); + ch=getchar(); + } + return head; + } + //ɾ³ýÄ£¿é + void *del() + { + SUB *p1,*p2; + char ch,ch1; + int num; + while(ch!='0') + { + printf("ÇëÊäÈëÏëɾ³ýµÄ¿Î³Ì±àºÅ:[ ]\b\b\b\b"); + scanf("%d",&num); + if(head->num==num); + { + p2=head; + head=head->next; + free(p2); + } + if(head==NULL) + return NULL; + p1=head; + p2=head->next; + while(p2) + { + if(p2->num==num) + { + p1->next=p2->next; + free(p2); + } + else + p1=p2; + p2=p1->next; + } + printf("\n¼ÌÐøɾ³ý°´»Ø³µ\n"); + printf("\n½áÊøɾ³ý°´ 0:[]\b\b"); + ch1=getchar(); + ch=getchar(); + } + return head; + system("pause"); + } + +//Ñ¡Ð޿γÌÄ£¿é +void choose() +{ + SUB *p,*q; + int a[5]; + int num,total=0,i=0,j; + printf("ÊäÈëÏëҪѡÐ޵Ŀγ̱àºÅ,±àºÅÖ®¼äÓÿոñ·Ö¿ª\n"); + scanf("%d",&num); + printf("Èç¹ûÈ·ÈÏÊäÈëÍêҪѡµÄ±àºÅ£¬ÇëÊäÈë 0:[]\n\n"); + while(num!=0) + { + for(p=head;p;p=p->next) + if(p->num==num) + { + total=total+p->score; + a[i]=num; + i++; + } + scanf("%d",&num); + } + if(total<60) + { + printf("Ñ¡ÐÞ×Üѧ·ÖΪ%d,δ´ïµ½60£¬Ñ¡ÐÞʧ°Ü£¡",total); + system("pause"); + } + else + { + FILE*fp; + fp=fopen("3.txt","w"); + for(j=0;jnext) + if(q->num==a[j]) + fprintf(fp,"%5d%12s%9s%9d%9d%11d%11d%7d\n",q->num,q->name,q->kind,q->stime,q->ttime,q->etime,q->score,q->term); + fclose(fp); + printf("\t\t\n*****Ñ¡Ð޳ɹ¦£¡*******\n"); + printf("\n ÄúÑ¡Ð޵ĿγÌ×Üѧ·ÖΪ%d,¿Î³Ì·Ö±ðΪ:\n",total); + printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉϼ¶Ñ§Ê± ѧ·Ö ¿ª¿ÎѧÆÚ\n"); + for(j=0;jnext) + if(q->num==a[j]) + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",q->num,q->name,q->kind,q->stime,q->ttime,q->etime,q->score,q->term); + printf("\nÒÔÉÏÐÅϢȫ²¿±£´æÔÚ'3.txt'ÖÐ\n"); + + } + system("pause"); + } + + //ÏÂÃ涨Òå²éѯ°å¿é + void search() + { + int a,num; + int t=1; + char type[10],min[10]; + SUB *ptr; + L1:system("cls"); + printf("\n\n\t\t***********ÇëÑ¡Ôñ²éѯ·½Ê½***********\n"); + printf("\n\t\t\t1--°´¿Î³ÌÃû³Æ²éÕÒ\n"); + printf("\n\t\t\t2--°´¿Î³ÌÐÔÖʲéÕÒ\n"); + printf("\n\t\t\t3--°´Ñ§·Ö²éÕÒ\n"); + printf("\n\t\t\t4-Í˳ö²éÕÒ\n"); + printf("\n\n\t\t************************************\n"); + printf("\n\nChoose your numeber(1-4):[]\b\b"); + scanf("%d",&a); + switch(a) + { + case 1:printf("ÊäÈë²éÕҿγÌÃû:"); + scanf("%s",min); + printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉÏ»úѧʱ ѧ·Ö ¿ª¿Îѧʱ\n"); + for(ptr=head;ptr;ptr=ptr->next) + if(strcmp(min,ptr->name)==0) + { + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); + t=0; + } + if(t) + printf("\t\n δÕÒµ½£¡\n"); + t=1; + system("pause"); + goto L1; + + + case 2:printf("ÇëÊäÈë²éÕҿγÌÐÔÖÊ:"); + scanf("%s",type); + printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉÏ»úѧʱ ѧ·Ö ¿ª¿Îѧʱ\n"); + for(ptr=head;ptr;ptr=ptr->next) + if(strcmp(type,ptr->kind)==0) + { + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); + t=0; + } + if(t) + printf("\t\n δÕÒµ½£¡\n"); + t=1; + system("pause"); + goto L1; + + case 3:printf("ÊäÈëÒª²éÕҵĿγ̵Äѧ·Ö:"); + scanf("%d",&num); + printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉÏ»úѧʱ ѧ·Ö ¿ª¿Îѧʱ\n"); + for(ptr=head;ptr;ptr=ptr->next) + if(ptr->score==num) + { + printf("%5d%12s%9s%9d%9d%11d%11d%7d\n",ptr->num,ptr->name,ptr->kind,ptr->stime,ptr->ttime,ptr->etime,ptr->score,ptr->term); + t=0; + } + if(t) + printf("\n\tδÕÒµ½£¡\n"); + t=1; + system("pause"); + goto L1; + + case 4:break; +} + } + //ÏÂÃ涨Òå¹ÜÀíÔ±°å¿é + void Mangers() + { + int n,w=1,flag=0,i=3; + char s[8]; + char password[7]="1";//ÃÜÂëΪ1 + do + { + printf("\n\nEnter password:");//ÊäÈëÃÜÂë + scanf("%s",s); + if(!strcmp(s,password))//ÃÜÂëÆ¥ÅäÑéÖ¤ + { + flag=1; + break;//ÊäÈëÕýÈ· + } + else + { + printf("\n\nError!You only have %d times!Pleasa enter again:\n",i-1); + i--; + } + } + while(i>0); + if(!flag) + { + printf("you have already entered 3 times!");//ÊäÈëÃÜÂ볬¹ý3´Î£¬Í˳ö + exit(0); + } + do + { + system("cls");//ÇåÆÁ + puts("\n\n\t\t*************¹Ü Àí Ô± ²Ë µ¥**************\n\n"); + puts("\t\t\t\t1--ä¯ÀÀ¿Î³Ì\n"); + puts("\t\t\t\t2--²éѯ¿Î³Ì\n"); + puts("\t\t\t\t3--Ìí¼Ó¿Î³Ì\n"); + puts("\t\t\t\t4--ɾ³ý¿Î³Ì\n"); + puts("\t\t\t\t5--·µ»ØÖ÷²Ëµ¥"); + puts("\n\n\t\t******************************************\n"); + printf("choose your number(1-5):[]\b\b"); + scanf("%d",&n); + switch(n) + { + case 1:prin();break;//ä¯ÀÀ + case 2:search();break;//²éѯ + case 3:insert();savefile();break;//Ìí¼Ó + case 4:del();savefile();break;//ɾ³ý + case 5:return; + default:; + } + }while(w==1); + } + +//ÏÂÃ涨ÒåѧÉú°å¿é +void Students() +{ + int n,w=1; + do + { + system("cls"); + puts("\n\n\t\t**********************************\n\n"); + puts("\t\t\t\t1--ä¯ÀÀËùÓпγÌ\n"); + puts("\t\t\t\t2--²éѯ¿Î³ÌÐÅÏ¢\n"); + puts("\t\t\t\t3--Ñ¡ÔñÑ¡Ð޿γÌ\n"); + puts("\t\t\t\t4--ä¯ÀÀÎÒÑ¡Ð޵ĿγÌ\n"); + puts("\t\t\t\t5--ɾ³ý´íÑ¡¿Î³Ì\n"); + puts("\t\t\t\t6--·µ»Ø"); + puts("\n\n\t\t****************************************\n"); + printf("choose your number(1-6):[]\b\b"); + scanf("%d",&n); + switch(n) + { + case 1:prin();break;//ä¯ÀÀ + case 2:search();break;//²éѯ + case 3:choose();break;//Ñ¡Ôñ + case 4:prin1();break;//ä¯ÀÀÎÒÑ¡ÐÞµÄ + case 5:del();savefile();break;//ɾ³ý´íÑ¡ + case 6:return;//·µ»Ø + default:; + } + } + while(w==1); + } + + + //ÏÂÃæ±à¼­Ö÷Ò³Ãæ + int main() + { + int n,w=1; + do + { + system("cls");//Çå³ýÆÁÄ» + puts("\n\n\t\t****************MENU****************\n\n"); + puts("\t\t\t\t1.ÒÔ¹ÜÀíÔ±Éí·ÝµÇ¼\n"); + puts("\t\t\t\t2.ÒÔѧÉúÉí·ÝµÇ¼\n"); + puts("\t\t\t\t3.Í˳ö"); + puts("\n\n\t\t***********************************\n"); + printf("Choose your number(1--3):[ ]\b\b"); + scanf("%d",&n); + switch(n) + { + case 1:Mangers();break;//Ñ¡1£¬½øÈë¹ÜÀíԱϵͳ + case 2:Students();break;//Ñ¡2£¬½øÈëѧÉúϵͳ + case 3:w=0;break;//Ñ¡3£¬Í˳ö + default:; + } + } + while(w==1); + return 0; + } + + + + + + + + + + + + + + + + + + + +