From c7685da250599775875a2a9cefa445e02c7fafa2 Mon Sep 17 00:00:00 2001 From: "1185759433@qq.com" <1185759433@qq.com> Date: Fri, 11 Jan 2019 19:13:59 +0800 Subject: [PATCH] 3 commit --- 第三次上传 .c | 404 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 404 insertions(+) create mode 100644 第三次上传 .c diff --git a/第三次上传 .c b/第三次上传 .c new file mode 100644 index 0000000..3afd73d --- /dev/null +++ b/第三次上传 .c @@ -0,0 +1,404 @@ +#define _CRT_SECURE_NO_WARNINGS +#include +#include //ÔÚʹÓÃÖÐÒªÓõ½µÄ×Ö·û´®¶¼°üº¬ÔÚ±¾ÎļþÖÐ +#include //exit()º¯Êý¾Í°üº¬ÔÚ´ËÎļþÖÐ +#include +#define isPrime(year) ((year%4==0&&year%100!=0)||(year%400==0)) + +int z[100]={0}; +int s,j; +FILE *fp; + + +void check_in(); //ÉùÃ÷µÇ¼ÇÈëסº¯Êý +void availability(); //ÉùÃ÷²éѯ·¿¼äÈëסÇé¿öº¯Êý +void fate_days(); //ÉùÃ÷²éѯÈÕÓÃסË޵ķÑÓà +void fate_hours(); //ÉùÃ÷²éѯʱÓÃסË޵ķÑÓà +void check_out_days(); //ÉùÃ÷½áÈÕÓÃסË޵ķÑÓà +void check_out_hours(); //ÉùÃ÷½áʱÓÃסË޵ķÑÓà +void modificate(); //ÉùÃ÷ÐÞ¸ÄÐÅÏ¢º¯Êý +void modificate_person(); //ÉùÃ÷ÐÞ¸ÄÐÅÏ¢º¯ÊýÖеÄÐ޸Ŀͻ§ÐÅÏ¢ +void modificate_accommodation(); //ÉùÃ÷ÐÞ¸ÄÐÅÏ¢º¯ÊýÖеÄÐÞ¸ÄסËÞÐÅÏ¢ +void save(); //ÉùÃ÷±£´æº¯Êý +void menu(); //ÉùÃ÷²Ëµ¥º¯Êý +void days(); //ÉùÃ÷ÈëסÀàÐÍΪÌìÊýº¯Êý +void hours(); //ÉùÃ÷ÈëסÀàÐÍΪСʱº¯Êý +int date1Diff(); //ÉùÃ÷¼ÆËãÌìÊý²îº¯Êý + + struct date1 +{ + int year; + int month; + int day; +}; + + +struct Date +{int year; +int month; +int day; +int hour; +int minute; +}date; //¶¨ÒåÈÕÆÚ±äÁ¿ + +struct room +{ +int room_ID; //·¿¼äºÅ +int kind; //·¿¼äÖÖÀࣨ°üº¬µ¥È˼䣬˫È˼䣬ÈýÈ˼䣬VIPÌ×·¿£© +char name[20]; //¿Í»§ÐÕÃû +int age; //¿Í»§ÄêÁä +int sex; //¿Í»§ÐÔ±ð +char ID_card[20]; //¿Í»§Éí·ÝÖ¤ºÅ +int day_money; //°´ÈÕÊշѼ۸ñ +int hour_money; //°´Ð¡Ê±ÊշѼ۸ñ +int count; //·¿¼äÊýÁ¿ +struct Date date; +}room[100]; + + int main() + { + + printf("\n"); + menu(); //°ÑÖ÷²Ëµ¥Óú¯ÊýÀ´ÊµÏÖ + save(); + return 0; +} + + + void menu() + { + int n; + do + { + printf("\n"); + printf(" \t ******************»¶Ó­Èëס¾Æµê***************** \n"); + printf("\n *********************²Ëµ¥********************"); + printf("\n******* 1.µÇ¼ÇÈëס \t *******\n"); + printf("******* 2.²éѯ·¿¼äÈëסÇé¿ö \t *******\n"); + printf("******* 3.²éѯµ±Ç°·ÑÓÃ(ÈÕÓÃ) \t *******\n"); + printf("******* 4.²éѯµ±Ç°·ÑÓÃ(ʱÓÃ) \t *******\n"); + printf("******* 5.½áÕ˵±Ç°·ÑÓÃ(ÈÕÓÃ) \t *******\n"); + printf("******* 6.½áÕ˵±Ç°·ÑÓÃ(ʱÓÃ) \t *******\n"); + printf("******* 7.Í˳ö \t *******"); + printf(" *********************²Ëµ¥********************\n"); //Êä³ö²Ëµ¥½çÃ棬ÈòÙ×÷Ô±Äܹ»·½±ãµÄÑ¡ÔñËùÐèÒª½øÐеIJÙ×÷ + printf("\n½ÓÏÂÀ´µÄ²Ù×÷ÖУ¬Èç¹ûÄúµÄÐÅÏ¢ÊäÈë´íÎó£¬ÇëÔÚÏÂÒ»²½Ê±ÊäÈë0£¬Ôò·µ»Ø²Ëµ¥£¬ÖØÐÂÑ¡Ôñ"); + printf("\nÇëÊäÈëÊý×ÖÀ´Ñ¡Ôñ²Ù×÷:"); + scanf("%d",&n); + while(n<1||n>7) + {printf(" *********************ÄúÊäÈëµÄÊý×ÖÓÐÎó£¬ÇëÖØÐÂÊäÈë¡£********************\n"); + scanf("%d",&n);} + switch(n) + { + case 1:check_in();break; //µ÷ÓõǼÇÈëסº¯Êý + case 2:availability();break; //µ÷Óòéѯ·¿¼äµÄÈëסÇé¿öº¯Êý + case 3:fate_days();break; //µ÷Óòéѯµ±Ç°ÈÕÓ÷ÑÓú¯Êý + case 4:fate_hours();break; //µ÷Óòéѯµ±Ç°Ê±Ó÷ÑÓú¯Êý + case 5:check_out_days();break; //µ÷ÓýáÕËÈÕÓ÷ÑÓú¯Êý + case 6:check_out_hours();break; //µ÷ÓýáÕ˵±Ç°Ê±Ó÷ÑÓú¯Êý + case 7:exit(0); //Í˳ö + } + }while(n!=7); +scanf("%d",&n); +} + +void check_in() // µÇ¼Çº¯Êý +{ + int op,way,po,i,num; + printf("ÇëÊäÈëÐèÒªµÄ·¿¼äÊýÁ¿£º"); + scanf("%d", &num); while(num<0||num>100) + {printf(" *********************ÄúÊäÈëµÄÊý×ÖÓÐÎó£¬ÇëÖØÐÂÊäÈë¡£********************\n"); + scanf("%d",&num);} + if(num==0) menu(); + for (i=1;i<=num;++i) { + printf("ÇëÊäÈëµÇ¼ÇÏà¹ØÐÅÏ¢:\n"); + printf("\n·¿¼ä%d·¿ºÅ£º(1ºÅµ½100ºÅÖ®¼ä)",i); + scanf("%d", &j);if(j==0) menu(); + room[j].room_ID = j; + printf("\nÇëÊäÈëÄêÁä:"); + scanf("%d", &room[j].age);if(room[j].age==0) menu(); + while (j<0||j>100) + { + printf("ÄúµÄÊäÈëÓÐÎó£¬ÇëÖØÐÂÊäÈë"); + } + printf("\nÇëÑ¡ÔñסËÞʱ¼äÀàÐÍ£º(1±íʾ°´Ìì¼Æ·Ñ£»2±íʾ°´Ð¡Ê±¼Æ·Ñ)\n\t *****×¢Ò⣺Èç¹ûÄúËù¾Óסʱ¼ä°üÀ¨ÁËÍíÉÏ£¬ÇëÄúÑ¡Ôñ°´Ìì¼Æ·Ñ*****"); + scanf("%d", &way);if(way==0) menu(); + printf("\nÈëסʱ¼äΪ(Äê):"); + scanf("%d", &room[j].date.year);if(room[j].date.year==0) menu(); + printf("\nÈëסʱ¼äΪ(ÔÂ):"); + scanf("%d", &room[j].date.month);if(room[j].date.month==0) menu(); + printf("\nÈëסʱ¼äΪ(ÈÕ):"); + scanf("%d", &room[j].date.day);if(room[j].date.day==0) menu(); + if (way == 1) + { + printf("\n·¿¼äÖÖÀࣺ[1´ú±íµ¥È˼ä(200Ôª/Ìì)£»2´ú±íË«È˼ä(390Ôª/Ìì)£»3´ú±íÈýÈ˼ä(475Ôª/Ìì)£»4´ú±íVIPÌ×·¿(650Ôª/Ìì)]"); + scanf("%d", &op);if(op==0) menu(); + } + if (way == 2) + { + printf("\n·¿¼äÖÖÀࣺ[1´ú±íµ¥È˼ä(10Ôª/Сʱ)£»2´ú±íË«È˼ä(19Ôª/Сʱ)£»3´ú±íÈýÈ˼ä(27Ôª/Сʱ)£»4´ú±íVIPÌ×·¿(45Ôª/Сʱ)]"); + scanf("%d", &po);if(po==0) menu(); + printf("\nÈëסʱ¼äΪ(Сʱ):"); + scanf("%d", &room[j].date.hour);if(room[j].date.hour==0) menu(); + printf("\nÈëסʱ¼äΪ(·ÖÖÓ):"); + scanf("%d", &room[j].date.minute);if(room[j].date.minute==0) menu(); + } + printf("\nÐÕÃû£º"); + scanf("%s", &room[j].name);if(room[j].name==0) menu(); + printf("\nÐÔ±ð(ÆäÖУº1±íʾÄУ¬2±íʾŮ!):"); + scanf("%d", &room[j].sex);if(room[j].sex==0) menu(); + printf("\nÉí·ÝÖ¤ºÅ£º"); + scanf("%s", &room[j].ID_card);if(room[j].ID_card==0) menu(); + z[j] = 1; //±ê¼ÇʹÓõķ¿¼äΪ1 + save(); + } + menu(); +} + + +void availability() //²éѯ·¿¼äÈëסÇé¿öº¯Êý +{ + int g,count=0; + for(g=0;g<100;g++) +{ + if(z[g]==0) + ++count; + else + if(z[g]==1) + printf("\nÕýÔÚʹÓõķ¿¼äºÅ:%d",g); +} + printf("\n\nδʹÓõķ¿¼äÊý:%d",count); //ͨ¹ýÑ­»·Êä³öδʹÓõķ¿¼äÊý + printf("\n\n"); + printf("\nÇëÊäÈëÐè²éѯµÄ·¿¼äºÅ: "); //²éѯÊäÈëµÄ·¿¼äºÅµÄÐÅÏ¢£¬ÇÒÊä³ö¸Ã·¿¼äµÄÏà¹ØÐÅÏ¢ + scanf("%d",&s); + while(s<0||s>100) + {printf(" *********************ÄúÊäÈëµÄÊý×ÖÓÐÎó£¬ÇëÖØÐÂÊäÈë¡£********************\n"); + scanf("%d",&s);}if(s==0) menu(); + if(z[s]==1) + {printf("ÐÕÃû:%s",room[s].name); + printf("\nÐÔ±ð(ÆäÖУº1±íʾÄУ¬2±íʾŮ):%d",room[s].sex); + printf("\nÄêÁä:%d",room[s].age); + printf("\nÉí·ÝÖ¤ºÅ:%s",room[s].ID_card); + printf("\nÄê:%d",room[s].date.year); + printf(" ÔÂ:%d",room[s].date.month); + printf(" ÈÕ:%d",room[s].date.day); + printf("\n·¿¼äºÅ:%d",room[s].room_ID); + } + else + printf("¸Ã·¿¼äδ±»Ê¹ÓÃ!"); + menu(); + save(); //µ÷Óñ£´æº¯Êý +} + + +void hours() +{ + int nu,numb; + int hour1,minute1; + int hour2,minute2; + printf("ÇëÊäÈëÈëסʱ¼ä£¨Ð¡Ê±,·ÖÖÓ£©"); + scanf("%d,%d",&hour1,&minute1);if(hour1==0||minute1==0) menu(); + printf("ÇëÊäÈëÍË·¿Ê±¼ä£¨Ð¡Ê±,·ÖÖÓ£©"); + scanf("%d,%d",&hour2,&minute2);if(hour2==0||minute2==0) menu(); + int t,t1,t2,o,q; + t1=hour1*60+minute1; + t2=hour2*60+minute2; + t=t2-t1; + o=t/60; + q=t%60; + if(q!=0) + o=o+1; + printf("ÄúÈëסµÄСʱΪ%dСʱ",o); + printf("\nÄúÑ¡ÔñµÄ·¿¼äÀàÐÍÊÇ£¨1´ú±íµ¥È˼䣬2´ú±íË«È˼䣬3´ú±íÈýÈ˼䣬4´ú±íVIPÌ×·¿£©£º "); + scanf("%d",&nu);if(nu==0) menu(); + printf("\nÄúÑ¡ÔñÁ˼¸¼äÌ×·¿£º "); + scanf("%d",&numb); + while(numb<1||numb>7) + {printf(" *********************ÄúÊäÈëµÄÊý×ÖÓÐÎó£¬ÇëÖØÐÂÊäÈë¡£********************\n"); + scanf("%d",&numb);} if(numb==0) menu(); + switch(nu) + { + case 1:printf("Äúµ±Ç°·ÑÓÃΪ %d Ôª",10*numb*o);break; + case 2:printf("Äúµ±Ç°·ÑÓÃΪ %d Ôª",19*numb*o);break; + case 3:printf("Äúµ±Ç°·ÑÓÃΪ %d Ôª",27*numb*o);break; + case 4:printf("Äúµ±Ç°·ÑÓÃΪ %d Ôª",45*numb*o);break; + } +} + + +int date1Diff(struct date1 mindate,struct date1 maxdate) +{ + int Days=0,j,flag; + const int primeMonth[][12]={{31,28,31,30,31,30,31,31,30,31,30,31},{31,29,31,30,31,30,31,31,30,31,30,31}}; + /************************************************************************/ + /* ½»»»Á½¸öÈÕÆÚº¯Êý,½«Ð¡µÄÈÕÆÚ¸ømindate,½«´óµÄÈÕÆÚ¸ømaxdate */ + /************************************************************************/ + struct date1 tmp; + if ((mindate.year>maxdate.year)|| (mindate.year==maxdate.year&&mindate.month>maxdate.month)||(mindate.year==maxdate.year&&mindate.month==maxdate.month&&mindate.day>maxdate.day)) + { + tmp=mindate; + mindate=maxdate; + maxdate=tmp; + } + /************************************************************************/ + /* ´Ómindate.year¿ªÊ¼ÀÛ¼Óµ½maxdate.year */ + /************************************************************************/ + for(j=mindate.year;j= 100) { + printf("·¿¼äºÅÊäÈëÓÐÎó\n"); + continue; + } + else + break; + } + printf("\t\t ***ÔÚÊäÈëÈÕÆÚ¹ý³ÌÖÐÇë²»ÒªÈÃ0ÔÚÊ×λ***"); + printf("\nÇëÊäÈëÈëסÈÕÆÚ£¨Ä꣬Ô£¬ÈÕ£©:"); + scanf("%i,%i,%i", &mindate.year, &mindate.month, &mindate.day);if(mindate.year==0||mindate.month==0||mindate.day==0) menu(); + printf("ÇëÊäÈëÍË·¿ÈÕÆÚ£¨Ä꣬Ô£¬ÈÕ£©:"); + scanf("%i,%i,%i", &maxdate.year, &maxdate.month, &maxdate.day);if(maxdate.year==0||maxdate.month==0||maxdate.day==0) menu(); + Days = date1Diff(mindate, maxdate); + printf("ÄúÈëסµÄÌìÊýΪ:%d\n", Days); + printf("\nÄúÑ¡ÔñµÄ·¿¼äÀàÐÍÊÇ£¨1´ú±íµ¥È˼䣬2´ú±íË«È˼䣬3´ú±íÈýÈ˼䣬4´ú±íVIPÌ×·¿£©£º "); + scanf("%d", &Un);if(Un==0) menu(); + switch (Un) + { + case 1:Mun+=(200*Days); break; + case 2:Mun += (290 * Days); break; + case 3:Mun+=(475*Days); break; + case 4:Mun += (650 * Days); break; + } + z[roomId] = 0; + memset(room + roomId, 0, sizeof(room)); + } + printf("Çë½ÉÄÉ %d Ôª", Mun); +} + +void check_out_hours() +{ + int Nu, Numb = 0,i; + int hour1,minute1; + int hour2,minute2; + int roomId; + int roomNum; + printf("ÇëÊäÈë·¿¼äÊýÁ¿£º"); + scanf("%i", &roomNum);if(roomNum==0) menu(); + for (i = 1; i <= roomNum; ++i) { + while (1) { + printf("\n·¿¼ä%d·¿ºÅ£º(1ºÅµ½100ºÅÖ®¼ä)", i); + scanf("%i", &roomId);if(roomId==0) menu(); + if (roomId < 0 || roomId >= 100) { + printf("·¿¼äºÅÊäÈëÓÐÎó\n"); + continue; + } + else + break; + } + printf("ÇëÊäÈëÈëסʱ¼ä£¨Ð¡Ê±,·ÖÖÓ£©"); + scanf("%d,%d", &hour1, &minute1);if(hour1==0||minute1==0) menu; + printf("ÇëÊäÈëÍË·¿Ê±¼ä£¨Ð¡Ê±,·ÖÖÓ£©"); + scanf("%d,%d", &hour2, &minute2);if(hour2==0||minute2==0) menu; + int t, t1, t2, o, q; + t1 = hour1 * 60 + minute1; + t2 = hour2 * 60 + minute2; + t = t2 - t1; + o = t / 60; + q = t % 60; + if (q != 0) + o = o + 1; + printf("ÄúÈëסµÄСʱΪ%dСʱ", o); + printf("\nÄúÑ¡ÔñµÄ·¿¼äÀàÐÍÊÇ£¨1´ú±íµ¥È˼䣬2´ú±íË«È˼䣬3´ú±íÈýÈ˼䣬4´ú±íVIPÌ×·¿£©£º "); + scanf("%d", &Nu);if(Nu==0) menu; + switch (Nu) + { + case 1:Numb+=(10*o);break; + case 2:Numb+=(19*o);break; + case 3:Numb+=(27*o);break; + case 4:Numb+=(45*o);break; + } + z[roomId]=0; + memset(room+roomId,0,sizeof(room)); + } + printf("Çë½ÉÄÉ %d Ôª", Numb); +} + + +void save() //±£´æº¯Êý +{ + FILE *fp; + int i; +if((fp=fopen("¿Í·¿¹ÜÀí.txt","w+"))==NULL) //´ò¿ªÊä³öÎļþ"¿Í·¿¹ÜÀí.txt" + {printf("cannot open file\n"); + exit(0); + } +for(i=0;i<100;i++) + { + if(fwrite((&room[i]), sizeof(room[100]),1,fp)!=1) + printf("file write error\n"); + fflush(fp); + } + fclose(fp); //¹Ø±ÕÎļþ +}