diff --git a/机房收费系统2.0.cpp b/机房收费系统2.0.cpp new file mode 100644 index 0000000..10aaf3e --- /dev/null +++ b/机房收费系统2.0.cpp @@ -0,0 +1,325 @@ +#include +#include +#include + +struct time +{ + int hour; + int minute; +}; + +struct student +{ + int no; + int classno; + char name[20]; + struct time begin,end; + struct student *next; +}; + +FILE *pf; +typedef struct student STU; +STU *create_student(); +void end_money(STU *head); +void select_no(STU *head); +void select_classno(STU *head); +void select_name(STU *head); +void add_student(STU *head); +void delect_student(STU *head); + +void printf_student(STU *head); +int menu_select(); + +void student_write(STU *head); +STU *student_read(); + +int main() +{ + STU *head; + int n=1,k=0; + while(n) + { + switch(menu_select()) + { + if(k==1) + { + head=student_read(); + } + case 1: + { + system("cls"); + head=create_student(); + student_write(head); + printf("³õʼ»¯ÐÅÏ¢³É¹¦£¡£¨ÐÅÏ¢Òѳɹ¦Â¼ÈëstudentÎļþ£©\n"); + k=1; + break; + } + case 2: + { + system("cls"); + end_money(head); + break; + } + case 3: + { + system("cls"); + select_no(head); + break; + } + case 4: + { + system("cls"); + select_classno(head); + break; + } + case 5: + { + system("cls"); + select_name(head); + break; + } + + case 7: + { + system("cls"); + add_student(head); + break; + } + case 8: + { + system("cls"); + delect_student(head); + break; + } + + case 0: + { + n=0; + printf("±¾´Î²Ù×÷³É¹¦£¬ÒѼÈëÔÚ°¸£¡\n"); + return 0; + break; + } + } + } + system("pause"); + return 0; +} + +int menu_select() +{ + int i; + printf("\t\t**************************************\t\t\n"); + printf("1.__³õʼ»¯Ñ§ÉúÐÅÏ¢\n"); + printf("2.__½áÕË\n"); + printf("3.__°´Ñ§ºÅ²éѯ\n"); + printf("4.__°´°à¼¶²éѯ\n"); + printf("5.__°´ÐÕÃû²éѯ\n"); + printf("6.__ÐÞ¸ÄѧÉúÉÏ»úµµ°¸\n"); + printf("7.__ÔöÌíѧÉúÐÅÏ¢\n"); + printf("8.__ɾ³ýѧÉúÐÅÏ¢\n"); + printf("9.__ÏÔʾȫ²¿ÉÏ»úѧÉúÐÅÏ¢\n"); + printf("0.__Í˳öϵͳ\n"); + printf("\t\t*****ÇëÑ¡ÔñÏëҪʵÏֵŦÄÜÐòºÅ*****\t\t\n"); + scanf("%d",&i); + return i; +} + +STU *create_student() +{ + STU *p,*head,*tail; + int no,classno,flag=1; + char name[20]; + int begin_hour,begin_minute,end_hour,end_minute; + while(flag) + { + p=(STU*)malloc(sizeof(STU)); + printf("ÇëÊäÈëѧºÅ"); + scanf("%d",&no); + printf("ÇëÊäÈë°à¼¶"); + scanf("%d",&classno); + printf("ÇëÊäÈëÐÕÃû"); + scanf("%s",&name); + printf("ÇëÊäÈëÉÏ»úʱ¼ä"); + scanf("%d%d",&begin_hour,&begin_minute); + printf("ÇëÊäÈëÏ»úʱ¼ä"); + scanf("%d%d",&end_hour,&end_minute); + p->no=no; + p->classno=classno; + strcpy(p->name,name); + p->begin.hour=begin_hour; + p->begin.minute=begin_minute; + p->end.hour=end_hour; + p->end.minute=end_minute; + p->next=NULL; + if(head==NULL) + { + head=p; + } + else + { + tail->next=p; + } + tail=p; + printf("Í£Ö¹ÊäÈëÇë°´0¼ÌÐøÊäÈëÇë°´1\n"); + scanf("%d",&flag); + } + return head; +} + + +void end_money(STU *head) +{ + STU *p; + float m,k=0.1; + int minute,hour; + int no; + printf("ÇëÊäÈëѧºÅ£º\n"); + scanf("%d",&no); + for(p=head;p;p=p->next) + { + if(no==p->no) + { + if(p->end.minutebegin.minute){ + p->begin.hour--; + minute=p->end.minute+60-p->begin.minute; + }else{ + minute=p->end.minute-p->begin.minute; + } + hour=p->end.hour-p->begin.hour; + minute=hour*60+minute; + m=minute*k; + printf("±¾´ÎÉÏ»úʱ¼äΪ%d·ÖÖÓ£¬Ïû·Ñ½ð¶îΪ%fÔª(×¢£ºÉÏ»ú0.1Ôª/·ÖÖÓ)\n",minute,m); + } + } + +} + +void select_no(STU *head) +{ + STU *p; + int no; + printf("ÇëÊäÈëѧºÅ£º\n"); + scanf("%d",&no); + for(p=head;p;p=p->next) + { + if(no==p->no) +printf("ѧºÅ£º%d°à¼¶£º%dÐÕÃû£º%sÉÏ»úʱ¼ä£º%d:%dÏ»úʱ¼ä£º%d:%d\n",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute); + } + +} + +void select_classno(STU *head) +{ + STU *p; + int classno; + printf("ÇëÊäÈë°à¼¶:\n"); + scanf("%d",&classno); + for(p=head;p;p=p->next) + { + if(classno==p->classno) +printf("ѧºÅ£º%d°à¼¶£º%dÐÕÃû£º%sÉÏ»úʱ¼ä£º%d:%dÏ»úʱ¼ä£º%d:%d\n",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute); + } + +} + +void select_name(STU *head) +{ + STU *p; + char name[20]; + printf("ÇëÊäÈëÐÕÃû:\n"); + scanf("%s",&name); + for(p=head;p;p=p->next) + { + if(strcmp(name,p->name)==0) +printf("ѧºÅ£º%d°à¼¶£º%dÐÕÃû£º%sÉÏ»úʱ¼ä£º%d:%dÏ»úʱ¼ä£º%d:%d\n",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute); + } +} + + + + + +void add_student(STU *head) +{ + STU *p,*q; + int no,classno,begin_hour,begin_minute,end_hour,end_minute; + char name[20]; + scanf("%d%d%s%d%d%d%d",&no,&classno,&name,&begin_hour,&begin_minute,&end_hour,&end_hour); + for(p=head;p;p=p->next) + { + if(p->next->next==NULL) + { + p->no=no; + p->classno=classno; + strcpy(p->name,name); + p->begin.hour=begin_hour; + p->begin.minute=begin_minute; + p->end.hour=end_hour; + p->end.minute=end_hour; + } + } +} + +void delect_student(STU *head) +{ + STU *p,*q; + int no; + p=head; + printf("ÇëÊäÈëѧºÅ\n"); + scanf("%d",&no); + if(p->next->no==no) + { + q=p->next; + p->next=q->next; + free(q); + } + + printf("ɾ³ý³É¹¦£¡\n"); +} + +void student_write(STU *head) +{ + STU *p; + int i; + p=head; + pf=fopen("student.txt","a+"); + if(pf!=NULL) + { + while(p) + { + fprintf(pf,"%d%d%s%d%d%d%d",p->no,p->classno,p->name,p->begin.hour,p->begin.minute,p->end.hour,p->end.minute); + p=p->next; + } + } + else + { + printf("error!\n"); + exit(0); + } + fclose(pf); +} + +STU *student_read() +{ + char name[20]; + int no,classno,begin_hour,begin_minute,end_hour,end_minute; + STU *head,*p,*q; + pf=fopen("student.txt","a+"); + head=p=(STU*)malloc(sizeof(STU)); + while(fscanf(pf,"%d%d%s%d%d%d%d",&no,&classno,&name,&begin_hour,&begin_minute,&end_hour,&end_minute)!=EOF) + { + q=(STU*)malloc(sizeof(STU)); + q->no=no; + q->classno=classno; + strcpy(q->name,name); + q->begin.hour=begin_hour; + q->begin.minute=begin_minute; + q->end.hour=end_hour; + q->end.minute=end_minute; + p->next=q; + p=q; + } + fclose(pf); + return head; +} + diff --git a/机房收费系统2.0.exe b/机房收费系统2.0.exe new file mode 100644 index 0000000..2a319a7 Binary files /dev/null and b/机房收费系统2.0.exe differ