From 4f318e2bd1c1c4bed5a0f2b2ebecda1ca60e8f22 Mon Sep 17 00:00:00 2001 From: 17773980884 <2578298389@qq.com> Date: Fri, 11 Jan 2019 22:35:01 +0800 Subject: [PATCH] first commit --- 选课系统.cpp | 321 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 321 insertions(+) create mode 100644 选课系统.cpp diff --git a/选课系统.cpp b/选课系统.cpp new file mode 100644 index 0000000..c2f79b1 --- /dev/null +++ b/选课系统.cpp @@ -0,0 +1,321 @@ +#include "stdio.h" +#include "string.h" +#include "stdlib.h" +#include"malloc.h" +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 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; +FILE *fp; +if((fp=fopen("3.txt","r"))==NULL) +{ +printf("Cannot open file.\n"); +choose(); +} +printf("¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉÏ»úѧʱ ѧ·Ö ¿ª¿ÎѧÆÚ\n"); +while(!feof(fp)) +{ +ptr=(SUB*)malloc(sizeof(SUB)); +fscanf(fp,"%d%s%s%d%d%d%d%d\n",&ptr->num,ptr->name,ptr->kind,&ptr->stime,&ptr->ttime,&ptr->etime,&ptr->score,&ptr->term); +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"); +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\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(); +printf("\nɾ³ýÍê±Ï,ÐÂÐÅÏ¢´æÈëÎļþÖÐ\n"); +system("pause"); +} +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: [ ]\b\b"); +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,Ñ¡ÐÞʧ°Ü!\n",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¿Î³Ì±àºÅ ¿Î³ÌÃû³Æ ¿Î³ÌÐÔÖÊ ×Üѧʱ ÊÚ¿Îѧʱ ʵ¼ù»òÉÏ»úѧʱ ѧ·Ö ¿ª¿ÎѧÆÚ\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\nChiose your number(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; +} +}