From a77abe199ee0eaa891bc6fa5808ae35c5f57962d Mon Sep 17 00:00:00 2001 From: 17773980884 <2578298389@qq.com> Date: Fri, 11 Jan 2019 22:39:12 +0800 Subject: [PATCH] third commit --- 学生选修课程系统设计2.c | 425 ++++++++++++++++++++++++++++++ 1 file changed, 425 insertions(+) create mode 100644 学生选修课程系统设计2.c diff --git a/学生选修课程系统设计2.c b/学生选修课程系统设计2.c new file mode 100644 index 0000000..341821a --- /dev/null +++ b/学生选修课程系统设计2.c @@ -0,0 +1,425 @@ +#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; +} +} +void Mangers() +{ +int n,w=1,flag=0,i=3; +char s[8]; +char password[7]="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! Enter again:\n",i-1); +i--; +} +} +while(i>0); +if(!flag) +{ +printf("you have Enter 3 times!"); +exit(0); +} +do +{ +system("cls"); +printf("\n\n\t\t*********************¹ÜÀíÔ±²Ëµ¥***********************\n\n"); +printf("\t\t\t\t1---ä¯ÀÀ¿Î³Ì\n"); +printf("\t\t\t\t2---²éѯ¿Î³Ì\n"); +printf("\t\t\t\t3---Ìí¼Ó¿Î³Ì\n"); +printf("\t\t\t\t4---ɾ³ý¿Î³Ì\n"); +printf("\t\t\t\t5---·µ»ØÖ÷²Ëµ¥"); +printf("\n\n\t\t******************************************************\n"); +printf("Chiose 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("Chiose 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();savefile1();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.ÒÔ¹ÜÀíÔ±Éí·ÝµÇ¼(password 1)\n"); +puts("\t\t\t\t2.ÒÔѧÉúÉí·ÝµÇ¼\n"); +puts("\t\t\t\t3.Í˳ö"); +puts("\n\n\t\t************************************************\n"); +printf("Chiose your number(1-3):[ ]\b\b"); +scanf("%d",&n); +switch(n) +{ +case 1:Mangers() ;break; +case 2:Students();break; +case 3:w=0;break; +default:; +} +} +while(w==1); +return 0; +} +