C語(yǔ)言實(shí)現(xiàn)酒店預(yù)訂管理系統(tǒng)
本文實(shí)例為大家分享了C語(yǔ)言實(shí)現(xiàn)酒店預(yù)訂管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
課設(shè)要求:
客房信息管理。
客人預(yù)訂及入住信息管理。
各種查詢和統(tǒng)計(jì)功能。
本系統(tǒng)要有通用性、界面美觀、操作方便。要考慮系統(tǒng)安全。 可增加其他有用的功能。
頭文件function.h
#pragma once #include <stdio.h> #include "struct.h" void color1();//背景顏色 void changecolor1();//修改背景顏色 void registers();//登錄,驗(yàn)證密碼 void showroomtype();//顯示房間類型 void inquirevacant();//查詢選擇的房間是否有空房,并輸出查詢結(jié)果。 void interface();//顯示界面 Room* readroom();//從文件里面讀出來(lái)room放到鏈表里面 void saveroom();//保存文件信息 void emptyroom();//清空一個(gè)房間 void inputroom();//填寫(xiě)一個(gè)房間 Order* exploitorderhead();//開(kāi)辟一個(gè)訂單頭 void chooseroomtype();//選擇房間類型 int judgeid();//判斷身份證號(hào)碼是否符合要求 int judgephone();//判斷電話號(hào)是否符合要求11位全數(shù)字 void openroom();//開(kāi)房 void saveorder();//保存訂單 Order* readorder();//讀取訂單 int Check_date1();//檢驗(yàn)日期是否合法 int Check_date2();//檢驗(yàn)日期是否合法 void deletedisabledorder();//刪除失效訂單 int Check_date3();//檢驗(yàn)日期是否合法 void checkchar();//將字符串后面的\n去掉 void checkchar1();//將字符串后面加上\n void changeorder();//修改訂單 void deleteorder();//刪除訂單 void changeKEY();//修改密碼 void search2();//查詢訂單 void search1();//查詢房間 void statistics();//統(tǒng)計(jì)訂單 int time_1();// 檢查訂單時(shí)間是否大于輸入時(shí)間 int Check_date4(); void read_();//讀取數(shù)據(jù) void backups();//備份 int FindSubstring();//查詢字串
頭文件struct.h
#pragma once typedef struct costomer { ?? ?char name[40]; ?? ?char idcard[20]; ?? ?char phonenumber[20]; }Costomer; typedef struct room { ?? ?char roomnumber[10]; ?? ?char type[10]; ?? ?int flag; ?? ?Costomer u; ?? ?struct room* rnext; ? }Room; typedef struct order { ?? ?Room* room_; ?? ?int hour[2]; ?? ?int day[2]; ?? ?int mon[2]; ?? ?int year[2]; ?? ?struct order* onext; }Order; typedef struct administrator { ?? ?char username[20]; ?? ?char password[20]; }Administrator;
function.c
#include "function.h" #include <stdlib.h > #include "struct.h" #include <string.h> #include <time.h> #include <windows.h> #include <stdio.h> extern Room* rhead; extern Order* ohead; void registers() { ?? ?time_t timep; ?? ?struct tm* p; ?? ?time(&timep); ?? ?p = gmtime(&timep); ?? ?char s[15], c[15]; ?? ?FILE* fp = fopen("password.txt", "r"); ?? ?if (fp == NULL) { ?? ??? ?printf("Failed to open file"); ?? ?} ?? ?fgets(s, 14, fp);//讀出文件中的密碼 ?? ?fclose(fp); ?? ?color1();//根據(jù)之前修改的顏色更新系統(tǒng)顏色 ?? ?printf("\n請(qǐng)輸入登錄密碼:"); ?? ?gets(c); ?? ?while (strcmp(c, s) != 0) { //判斷密碼是否正確,不正確的話重新輸入。 ?? ??? ?printf("\n密碼錯(cuò)誤請(qǐng)重試"); ?? ??? ?gets(c); ?? ?} ?? ?if (strcmp(c, s) == 0) { ?? ??? ?read_(); ?? ??? ?while (1) ?? ??? ?{ ? ?? ??? ??? ?system("cls");//清空界面 ?? ??? ??? ?color1();//根據(jù)之前修改的顏色更新系統(tǒng)顏色 ?? ??? ??? ?printf("\n\n\n\n"); ?? ??? ??? ?printf(" ***********************************************\n"); ?? ??? ??? ?printf(" ^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ^_^\n"); ?? ??? ??? ?printf(" ***********************************************\n"); ?? ??? ??? ?printf("_______________________________________________\n"); ?? ??? ??? ?printf("┃ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?┃\n"); ?? ??? ??? ?printf("┃ ? ? ? ? ? ? ?酒店預(yù)約管理系統(tǒng) ? ? ? ? ? ? ?┃\n"); ?? ??? ??? ?printf("┃ ? ? ? ? ? ?歡迎來(lái)到白山黑水酒店! ? ? ? ? ?┃\n"); ?? ??? ??? ?printf("┃ ? ? ? ? ? ?現(xiàn)在是%d年", 1900 + p->tm_year);/*獲取當(dāng)前年份,從知1900開(kāi)始,所以要加1900*/ ?? ??? ??? ?printf("%d月", 1 + p->tm_mon);/*獲取當(dāng)前月份,范圍是0-11,所以要加1*/ ?? ??? ??? ?printf("%d日", p->tm_mday);/*獲取當(dāng)前月份日數(shù),范圍是1-31*/ ?? ??? ??? ?printf("%d時(shí)", 8 + p->tm_hour);/*獲取當(dāng)前時(shí),這里獲取西方的時(shí)百間,剛好相差八個(gè)度小時(shí)*/ ?? ??? ??? ?printf(" ? ? ? ? ┃\n"); ?? ??? ??? ?printf("┃ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?┃\n"); ?? ??? ??? ?printf("┃ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?┃\n"); ?? ??? ??? ?printf("┃____________________________________________┃\n"); ?? ??? ??? ?printf("***********************************************\n"); ?? ??? ??? ?printf("***********************************************\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?1.客戶入住信息登記 ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?2.修改背景顏色 ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?3.修改密碼 ? ? ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?4.查詢信息 ? ? ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?5.修改訂單信息 ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?6.刪除訂單 ? ? ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?7.統(tǒng)計(jì)信息 ? ? ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?8.備份 ? ? ? ? ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("** ? ? ? ? ? ?9.退出并保存 ? ? ? ? ? ? ? ? ? **\n"); ?? ??? ??? ?printf("***********************************************\n"); ?? ??? ??? ?printf("***********************************************\n"); ?? ??? ??? ?printf("***********************************************\n"); ?? ??? ??? ?printf("^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ?^_^ ^_^\n"); ?? ??? ??? ?printf("***********************************************\n"); ?? ??? ??? ?printf(" ? ? ? ? ? ? ? 選擇操作:"); ?? ??? ??? ?int m; ?? ??? ??? ?char t[20]; ?? ??? ??? ?scanf("%d", &m); ?? ??? ??? ?while (m < 1 || m>9) { printf("\n請(qǐng)按要求輸入"); scanf("%d", &m); } ?? ??? ??? ?if (m== 9) ?? ??? ??? ?{ ?? ??? ??? ??? ?saveorder(); ?? ??? ??? ??? ?saveroom(); ?? ??? ??? ?} ?? ??? ??? ?switch (m) { ?? ??? ??? ?case 1: { chooseroomtype(); break; } ?? ??? ??? ?case 2: {changecolor1(); break; } ?? ??? ??? ?case 3:changeKEY(); break; ?? ??? ??? ?case 4: { {system("cls"); ?? ??? ??? ??? ?printf("選擇查詢類別:\n"); ?? ??? ??? ??? ?printf("1.查詢房間信息\n"); ?? ??? ??? ??? ?printf("2.查詢訂單信息\n"); ?? ??? ??? ??? ?printf("輸入選項(xiàng):"); ?? ??? ??? ??? ?gets(t); ?? ??? ??? ??? ?while ((strcmp(t, "1") != 0) && (strcmp(t, "2") != 0)) { ?? ??? ??? ??? ??? ?printf("\n請(qǐng)按要求輸入\n"); ?? ??? ??? ??? ??? ?gets(t); ?? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if ((strcmp(t, "1") == 0))search1();//查詢房間 ?? ??? ??? ??? ?if ((strcmp(t, "2") == 0))search2();//查詢訂單 ?? ??? ??? ??? ?}; break; } ?? ??? ??? ?case 5: {changeorder(); break; } ?? ??? ??? ?case 6: {deleteorder(); break; } ?? ??? ??? ?case 7: {statistics(); break; } ?? ??? ??? ?case 8: {backups(); break; } ?? ??? ??? ?case 9: {exit(0); break; } ?? ??? ??? ?? ?? ??? ??? ?} ?? ??? ?} ? ?? ?} } Room* readroom()//從文件里面讀出來(lái)room放到鏈表里面 { ?? ?FILE* fp = NULL; ?? ?char ch; ?? ?Room* rhead; ?? ?rhead = (Room*)malloc(sizeof(Room)); ?? ?if (rhead != NULL) ?? ?{ ?? ??? ?rhead->rnext = NULL; ?? ?} ?? ?Room* p = rhead; ?? ?Room* q = rhead; ?? ?if ((fp = fopen("room.txt", "r+")) == NULL) ?? ?{ ?? ??? ?printf("can't open the file\n"); ?? ??? ?system("pause"); ?? ??? ?return NULL; ?? ?} ?? ?while (!feof(fp)) ?? ?{ ?? ??? ?p = (Room*)malloc(sizeof(Room)); ?? ??? ?fgets(p->roomnumber, 20, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ?//printf("%s\n",p->roomnumber); ?? ??? ?fgets(p->type, 20, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ?//printf("%s\n",p->type); ?? ??? ?fscanf(fp, "%d", &(p->flag)); ?? ??? ?//printf("%d\n",p->flag); ?? ??? ?ch = fgetc(fp); ?? ??? ?ch = fgetc(fp); ?? ??? ?q->rnext = p; ?? ??? ?q = p; ?? ?} ?? ?q->rnext = NULL; ?? ?fclose(fp); ?? ?return rhead;//返回指針的頭 } void saveroom() { ?? ?FILE* fp = NULL; ?? ?Room* p = rhead->rnext; ?? ?if ((fp = fopen("room.txt", "w")) == NULL) ?? ?{ ?? ??? ?printf("can't open the room file\n"); ?? ??? ?system("pause"); ?? ?} ? ?? ?while (p != NULL) { ?? ??? ?fputs(p->roomnumber, fp); ?? ??? ?fputs(p->type, fp); ?? ??? ?fprintf(fp, "%d", p->flag); ?? ??? ?fputc('\n', fp); ?? ??? ?if (p->rnext != NULL)fputc('\n', fp); ?? ??? ?p = p->rnext; ?? ?} ?? ?fclose(fp); } void emptyroom(char roomnumber_[10])//清空一個(gè)房間 { ?? ?Room* p = rhead->rnext; ?? ?while (p != NULL) { ?? ??? ?if (strcmp(roomnumber_, p->roomnumber) == 0) { ?? ??? ??? ?p->flag = 0; ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?p = p->rnext; ? ?? ?} } int judgeid(char t[]) { ?? ?int flag = 0; ?? ?int i = 0; ?? ?for (i = 0; i < 18; i++) { ?? ??? ?if (i <= 16) ?? ??? ??? ?if (t[i] < '9' && t[i]>'0')flag = 0; ?? ??? ??? ?else flag = 1; ?? ??? ?if (i == 17) ?? ??? ??? ?if (t[i] == 'X' || (t[i] < '9' && t[i]>'0')) ?? ??? ??? ??? ?flag = 0; ?? ??? ??? ?else flag = 1; ?? ?} ?? ?return flag;//身份證號(hào)碼符合規(guī)則的話返回0,else返回1. } int judgephone(char t[]) { ?? ?int flag = 0; ?? ?int i = 0; ?? ?for (i = 0; i < 11; i++) { ? ?? ??? ?if (t[i] <= '9' && t[i] >= '0')flag = 0; ?? ??? ?else flag = 1; ?? ?} ?? ?return flag;//電話號(hào)符合規(guī)則的話返回0,else返回1. } Order* exploitorderhead() { ?? ?ohead = (Order*)malloc(sizeof(Order)); ?? ?if (ohead != NULL) ?? ?{ ?? ??? ?ohead->onext = NULL; ?? ??? ?return ohead; ?? ?} ?? ?else ?? ??? ?printf("開(kāi)辟訂單頭失敗\n"); } void chooseroomtype() { ?? ?char c[20]; ?? ?char choice[10]; ?? ?while (1) { ?? ??? ?system("cls"); ?? ??? ?printf("房間類型:\n"); ?? ??? ?printf("1.single\n"); ?? ??? ?printf("2.double\n"); ?? ??? ?printf("3.triple\n"); ?? ??? ?printf("4.four\n"); ?? ??? ?printf("5.返回上一層\n"); ?? ??? ?printf("請(qǐng)輸入你的選擇:"); ?? ??? ?fflush(stdin); ?? ??? ?rewind(stdin); ?? ??? ?gets(c); ?? ??? ?while ((strcmp(c, "1") != 0) && (strcmp(c, "2") != 0) && (strcmp(c, "3") != 0) && (strcmp(c, "4") != 0) && (strcmp(c, "5") != 0)) { ?? ??? ??? ?printf("選擇有誤,請(qǐng)重新輸入:"); ?? ??? ??? ?gets(c); ?? ??? ?} ?? ??? ?{ ?? ??? ??? ?if (strcmp(c, "1") == 0) { ?? ??? ??? ??? ?strcpy(choice, "single\n"); ?? ??? ??? ??? ?openroom(choice); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(c, "2") == 0) { ?? ??? ??? ??? ?strcpy(choice, "double\n"); ?? ??? ??? ??? ?openroom(choice); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(c, "3") == 0) { ?? ??? ??? ??? ?strcpy(choice, "triple\n"); ?? ??? ??? ??? ?openroom(choice); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(c, "4") == 0) { ?? ??? ??? ??? ?strcpy(choice, "four\n"); ?? ??? ??? ??? ?openroom(choice); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(c, "5") == 0) { ?? ??? ??? ??? ?break; ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ?? ??? ?} ?? ?} ? } void inquirevacant(char c[]) { ?? ?int flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0; ?? ?Room* p = rhead; ?? ?while (p != NULL) { ?? ??? ?if (p->flag == 0) { ?? ??? ??? ?if (strcmp(p->type, "single\n") == 0) ?? ??? ??? ??? ?flag1++; ?? ??? ??? ?if (strcmp(p->type, "double\n") == 0) ?? ??? ??? ??? ?flag2++; ?? ??? ??? ?if (strcmp(p->type, "triple\n") == 0) ?? ??? ??? ??? ?flag3++; ?? ??? ??? ?if (strcmp(p->type, "four\n") == 0) ?? ??? ??? ??? ?flag4++; ?? ??? ?} ?? ??? ?p = p->rnext; ? ?? ?} ?? ?if (strcmp(c, "single\n") == 0) ?? ?{ ?? ??? ?if (flag1 >= 1) { ?? ??? ??? ?printf("房間類型選擇成功\n"); ?? ??? ??? ?openroom(c); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?printf("抱歉,該類房間沒(méi)有空房,請(qǐng)重新選擇"); ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ??? ?chooseroomtype(); ? ?? ??? ?} ?? ?} ?? ?if (strcmp(c, "double\n") == 0) ?? ?{ ?? ??? ?if (flag2 >= 1) { ?? ??? ??? ?printf("房間類型選擇成功\n"); ?? ??? ??? ?openroom(c); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?printf("抱歉,該類房間沒(méi)有空房,請(qǐng)重新選擇"); ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ??? ?chooseroomtype(); ?? ??? ?} ?? ?} ?? ?if (strcmp(c, "triple\n") == 0) ?? ?{ ?? ??? ?if (flag3 >= 1) { ?? ??? ??? ?printf("房間類型選擇成功\n"); ?? ??? ??? ?openroom(c); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?printf("抱歉,該類房間沒(méi)有空房,請(qǐng)重新選擇"); ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ??? ?chooseroomtype(); ?? ??? ?} ?? ?} ?? ?if (strcmp(c, "four\n") == 0) ?? ?{ ?? ??? ?if (flag4 >= 1) { ?? ??? ??? ?printf("房間類型選擇成功\n"); ?? ??? ??? ?openroom(c); ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?printf("抱歉,該類房間沒(méi)有空房,請(qǐng)重新選擇"); ?? ??? ??? ?system("pause"); ?? ??? ??? ?system("cls"); ?? ??? ??? ?chooseroomtype(); ?? ??? ?} ?? ?} } void openroom(char t[]) { ?? ?Room* p = rhead; ?? ?Order* op = ohead; ?? ?while (op->onext != NULL) { ?? ??? ?op = op->onext; ?? ?}//找到指針末尾。 ?? ?Order* oop = (Order*)malloc(sizeof(Order)); ?? ?op->onext = oop; ?? ?oop->onext = NULL; ?? ?char id[40]; ?? ?char phonenumber_[20]; ?? ?while (p != NULL) { ?? ??? ?if (p->flag == 0 && strcmp(p->type, t) == 0) { ?? ??? ??? ?p->flag = 1; ?? ??? ??? ?oop->room_ = p; ?? ??? ??? ?printf("請(qǐng)輸入房主姓名:"); ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?scanf("%s", p->u.name); ?? ??? ??? ?checkchar1(p->u.name);//加上\n方便以后判斷 ?? ??? ??? ?printf("請(qǐng)輸入18位的身份證號(hào)碼:"); ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?scanf("%s", id); ?? ??? ??? ?while (strlen(id) != 18 || judgeid(id) != 0) {//判斷身份證號(hào)是否符合規(guī)則。 ?? ??? ??? ??? ?printf("身份證號(hào)碼格式有誤,請(qǐng)重新輸入:"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?scanf("%s", id); ?? ??? ??? ?} ?? ??? ??? ?checkchar1(id);//加上\n方便以后判斷 ?? ??? ??? ?strcpy(p->u.idcard, id); ?? ??? ??? ?printf("請(qǐng)輸入11位電話號(hào):"); ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?scanf("%s", phonenumber_); ?? ??? ??? ?while (strlen(phonenumber_) != 11 || judgephone(phonenumber_) != 0) ?? ??? ??? ?{//判斷電話號(hào)號(hào)是否符合規(guī)則。 ?? ??? ??? ??? ?printf("電話號(hào)不符合要求,請(qǐng)重新輸入:"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?scanf("%s", phonenumber_); ?? ??? ??? ?} ?? ??? ??? ?checkchar1(phonenumber_);//加上\n方便以后判斷 ?? ??? ??? ?strcpy(p->u.phonenumber, phonenumber_); ?? ??? ??? ?printf("請(qǐng)輸入入住時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?while ((scanf("%d/%d/%d/%d", &oop->year[0], &oop->mon[0], &oop->day[0], &oop->hour[0])) != 4 || Check_date1(oop->year, oop->mon, oop->day, oop->hour) != 0) {//判斷日期是否大于當(dāng)前日期 ?? ??? ??? ??? ?printf("日期輸入有誤,"); ?? ??? ??? ??? ?printf("請(qǐng)重新輸入入住時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ?} ?? ??? ??? ?printf("請(qǐng)輸入離開(kāi)時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?while ((scanf("%d/%d/%d/%d", &oop->year[1], &oop->mon[1], &oop->day[1], &oop->hour[1])) != 4 || Check_date2(oop->year, oop->mon, oop->day, oop->hour) != 0) {//判斷離開(kāi)日期是否入住當(dāng)前日期 ?? ??? ??? ??? ?printf("日期輸入有誤,"); ?? ??? ??? ??? ?printf("請(qǐng)重新輸入離開(kāi)時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ?} ?? ??? ??? ?printf("您的房間號(hào)碼:%s", p->roomnumber); ?? ??? ??? ?printf("創(chuàng)建訂單成功\n"); ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?p = p->rnext; ?? ?} ?? ?system("pause"); } void showroomtype() { ?? ?system("cls"); ?? ?printf("房間類型:\n"); ?? ?printf("1.single\n"); ?? ?printf("2.double\n"); ?? ?printf("3.triple\n"); ?? ?printf("4.four\n"); } void saveorder() { ?? ?FILE* fp = NULL; ?? ?if ((fp = fopen("order.txt", "w")) == NULL) ?? ?{ ?? ??? ?printf("can't built the order file\n"); ?? ??? ?system("pause"); ?? ?} ?? ?Order* p = ohead->onext; ?? ?while (p != NULL) { ?? ??? ?fputs(p->room_->roomnumber, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->type, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->u.name, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->u.idcard, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->u.phonenumber, fp);//連換行符一起保存 ?? ??? ?fprintf(fp, "%d", p->year[0]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->mon[0]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->day[0]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->hour[0]); ?? ??? ?fputc('\n', fp); ?? ??? ?fprintf(fp, "%d", p->year[1]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->mon[1]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->day[1]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->hour[1]); ?? ??? ?fputc('\n', fp); ?? ??? ?if (p->onext != NULL)fputc('\n', fp); ?? ??? ?p = p->onext; ?? ?} ?? ?fclose(fp); ? } Order* readorder() { ?? ?FILE* fp = NULL; ?? ?char ch; ?? ?Order* ohead = exploitorderhead(); ?? ?Order* p = ohead; ?? ?Order* q = ohead; ?? ?Room* u; ?? ?if ((fp = fopen("order.txt", "r+")) == NULL) ?? ?{ ?? ??? ?printf("can't open the file\n"); ?? ??? ?system("pause"); ?? ??? ?return NULL; ?? ?} ?? ?ch = fgetc(fp); ?? ?if (!feof(fp)) { ?? ??? ?rewind(fp); ?? ??? ?while (!feof(fp)) ?? ??? ?{ ?? ??? ??? ?p = (Order*)malloc(sizeof(Order)); ?? ??? ??? ?u = (Room*)malloc(sizeof(Room)); ?? ??? ??? ?p->room_ = u; ?? ??? ??? ?fgets(p->room_->roomnumber, 40, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p->room_->type, 10, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p->room_->u.name, 40, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p->room_->u.idcard, 20, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p->room_->u.phonenumber, 20, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fscanf(fp, "%d/%d/%d/%d", &p->year[0], &p->mon[0], &p->day[0], &p->hour[0]); ?? ??? ??? ?ch = fgetc(fp); ?? ??? ??? ?fscanf(fp, "%d/%d/%d/%d", &p->year[1], &p->mon[1], &p->day[1], &p->hour[1]); ?? ??? ??? ?ch = fgetc(fp); ?? ??? ??? ?ch = fgetc(fp); ?? ??? ??? ?q->onext = p; ?? ??? ??? ?q = p; ?? ??? ?} ?? ?} ?? ?q->onext = NULL; ?? ?fclose(fp); ?? ?return ohead; } int Check_date1(int year_[2], int month_[2], int date_[2], int hour_[2]) { ?? ?int flag = 0; ?? ?time_t timep; ?? ?struct tm* p; ?? ?time(&timep); ?? ?p = gmtime(&timep); ?? ?/*printf("%d\n", p->tm_sec); 獲取當(dāng)前秒 ?? ?printf("%d\n", p->tm_min);獲取當(dāng)前分 ?? ?printf("%d\n", 8 + p->tm_hour);獲取當(dāng)前時(shí),這里獲取西方的時(shí)間,剛好相差八個(gè)小時(shí) ?? ?printf("%d\n", p->tm_mday);獲取當(dāng)前月份日數(shù),范圍是1-31 ?? ?printf("%d\n", 1 + p->tm_mon);獲取當(dāng)前月份,范圍是0-11,所以要加1 ?? ?printf("%d\n", 1900 + p->tm_year);獲取當(dāng)前年份,從1900開(kāi)始,所以要加1900 ?? ?printf("%d\n", p->tm_yday); 從今年1月1日算起至今的天數(shù),范圍為0-36*/ ?? ?unsigned char Month_buf[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; ?? ?if (month_[0] == 2) ?? ??? ?(((year_[0] % 4 == 0) && (year_[0] % 100 != 0)) || (year_[0] % 400 == 0)) ? Month_buf[1] += 1 : Month_buf[1]; ? ?? ?if (month_[0] > 12 || month_[0]<1 || date_[0]>Month_buf[month_[0] - 1] || date_[0] < 1 || hour_[0] < 0 || hour_[0]>23) ?? ?{ ?? ??? ?flag = 1; ?? ??? ?return flag; ?? ?} ?? ?if (year_[0] < p->tm_year + 1900)flag = 1; ?? ?else if (year_[0] == p->tm_year + 1900) { ?? ??? ?if (month_[0] < p->tm_mon + 1)flag = 1; ?? ??? ?else if (month_[0] == p->tm_mon + 1) { ?? ??? ??? ?if (date_[0] < p->tm_mday)flag = 1; ?? ??? ??? ?else if (date_[0] == p->tm_mday) { ?? ??? ??? ??? ?if (hour_[0] < 8 + p->tm_hour)flag = 1; ?? ??? ??? ??? ?else if (hour_[0] == 8 + p->tm_hour)flag = 0; ?? ??? ??? ??? ?else if (hour_[0] > 8 + p->tm_hour)flag = 0; ?? ??? ??? ?} ?? ??? ??? ?else if (date_[0] > p->tm_mday)flag = 0; ?? ??? ?} ?? ??? ?else if (month_[0] > p->tm_mon + 1)flag = 0; ?? ?} ?? ?else if (year_[0] > p->tm_year + 1900)flag = 0; ? ?? ?return flag;//返回0是輸入日期大于當(dāng)前日期,1是輸入日期小于當(dāng)前日期 } int Check_date2(int year_[2], int month_[2], int date_[2], int hour_[2]) { ?? ?? ?? ?unsigned char Month_buf[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; ?? ?if (month_[1] == 2) ?? ??? ?(((year_[1] % 4 == 0) && (year_[1] % 100 != 0)) || (year_[1] % 400 == 0)) ? Month_buf[1] += 1 : Month_buf[1]; ? ?? ?if (month_[1] > 12 || month_[1]<1 || date_[1]>Month_buf[month_[1] - 1] || date_[1] < 1 || hour_[1] < 0 || hour_[1]>23)return 1; ?? ?? ?? ?if (year_[0] < year_[1])return 0; ?? ?else if (year_[0] == year_[1]) { ?? ??? ?if (month_[0] < month_[1])return 0; ?? ??? ?else if (month_[0] == month_[1]) { ?? ??? ??? ?if (date_[0] < date_[1])return ?0; ?? ??? ??? ?else if (date_[0] == date_[1]) { ?? ??? ??? ??? ?if (hour_[0] < hour_[1])return ?0; ?? ??? ??? ??? ?else if (hour_[0] == hour_[1]) return 1; ?? ??? ??? ??? ?else if (hour_[0] > hour_[1])return 1; ?? ??? ??? ?} ?? ??? ??? ?else if (date_[0] > date_[1])return 1; ?? ??? ?} ?? ??? ?else if (month_[0] > month_[1])return 1; ?? ?} ?? ?else if (year_[0] > year_[1])return 1; ? ?? ? //返回0是離開(kāi)日期大于入住日期,1是離開(kāi)日期小于入住日期 } int Check_date3(int year, int month, int date, int hour) { ?? ?int flag = 0; ?? ?time_t timep; ?? ?struct tm* p; ?? ?time(&timep); ?? ?p = gmtime(&timep); ?? ?if (year < p->tm_year + 1900)flag = 0; ?? ?else if (year == p->tm_year + 1900) { ?? ??? ?if (month < p->tm_mon + 1)flag = 0; ?? ??? ?else if (month == p->tm_mon + 1) { ?? ??? ??? ?if (date < p->tm_mday)flag = 0; ?? ??? ??? ?else if (date == p->tm_mday) { ?? ??? ??? ??? ?if (hour < 8 + p->tm_hour)flag = 0; ?? ??? ??? ??? ?else if (hour == 8 + p->tm_hour)flag = 0; ?? ??? ??? ??? ?else if (hour > 8 + p->tm_hour)flag++; ?? ??? ??? ?} ?? ??? ??? ?else if (date > p->tm_mday)flag++; ?? ??? ?} ?? ??? ?else if (month > p->tm_mon + 1)flag++; ?? ?} ?? ?else if (year > p->tm_year + 1900)flag++; ? ?? ?return flag;//返回1是離開(kāi)日期大于現(xiàn)在日期,0是離開(kāi)日期小于現(xiàn)在日期 } int Check_date4(int year_, int month_, int date_, int hour_) { ?? ?int flag = 0; ?? ?time_t timep; ?? ?struct tm* p; ?? ?time(&timep); ?? ?p = gmtime(&timep); ? ?? ?unsigned char Month_buf[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 }; ?? ?if (month_ == 2) ?? ??? ?(((year_ % 4 == 0) && (year_ % 100 != 0)) || (year_ % 400 == 0)) ? Month_buf[1] += 1 : Month_buf[1]; ? ?? ?if (month_ > 12 || month_<1 || date_>Month_buf[month_ - 1] || date_ < 1 || hour_ < 0 || hour_>23) ?? ?{ ?? ??? ?flag++; ?? ??? ?return flag; ?? ?} ?? ?if (year_ < p->tm_year + 1900)flag++; ?? ?else if (year_ == p->tm_year + 1900) { ?? ??? ?if (month_ < p->tm_mon + 1)flag++; ?? ??? ?else if (month_ == p->tm_mon + 1) { ?? ??? ??? ?if (date_ < p->tm_mday)flag++; ?? ??? ??? ?else if (date_ == p->tm_mday) { ?? ??? ??? ??? ?if (hour_ < 8 + p->tm_hour)flag++; ?? ??? ??? ??? ?else if (hour_ == 8 + p->tm_hour)flag = 0; ?? ??? ??? ??? ?else if (hour_ > 8 + p->tm_hour)flag = 0; ?? ??? ??? ?} ?? ??? ??? ?else if (date_ > p->tm_mday)flag = 0; ?? ??? ?} ?? ??? ?else if (month_ > p->tm_mon + 1)flag = 0; ?? ?} ?? ?else if (year_ > p->tm_year + 1900)flag = 0; ?? ?return flag;//返回0是輸入日期大于當(dāng)前日期,1是輸入日期小于當(dāng)前日期 } void deletedisabledorder() { ?? ?Order* p; ?? ?Order* q; ?? ?p = ohead; ?? ?int m = 0; ?? ?q = p->onext; ?? ?while (q != NULL) { ?? ??? ?if (Check_date3(q->year[1], q->mon[1], q->day[1], q->hour[1]) != 1)//判斷訂單是否失效 ?? ??? ?{ ?? ??? ??? ?emptyroom(q->room_->roomnumber);//把房間狀態(tài)清除 ?? ??? ??? ?p->onext = q->onext; ?? ??? ??? ?free(q); ?? ??? ??? ?q = p->onext; ?? ??? ??? ?m++; ?? ??? ?} ?? ??? ?else { ?? ??? ??? ?p = p->onext; ?? ??? ??? ?q = q->onext; ?? ??? ?} ?? ?} ?? ?if (m != 0)printf("失效訂單已刪除\n"); ?? ?else ?? ??? ?printf("當(dāng)前無(wú)失效訂單\n"); } void checkchar(char t[]) { ?? ?int i; ?? ?for (i = 0;; i++) { ?? ??? ?if (t[i] == '\n') { ?? ??? ??? ?t[i] = '\0'; ?? ??? ??? ?break; ?? ??? ?} ?? ?} ? } void checkchar1(char t[]) { ?? ?int i; ?? ?for (i = 0;; i++) { ?? ??? ?if (t[i] == '\0') { ?? ??? ??? ?t[i] = '\n'; ?? ??? ??? ?t[i + 1] = '\0';//添加換行符 ?? ??? ??? ?break; ?? ??? ?} ?? ?} } void changeorder()//修改訂單 { ?? ?system("cls"); ?? ?char phonenumber_[20]; ?? ?char id[40]; ?? ?Order* p; ?? ?char num[20]; ?? ?int m = 0, m1 = 0; ?? ?if (ohead->onext == NULL) ?? ?{ ?? ??? ?printf("訂單為空修改失敗\n"); ?? ??? ?system("pause"); ?? ?} ?? ?else ?? ?{ ?? ??? ?p = ohead->onext; ?? ??? ?char nam[20]; ?? ??? ?printf("輸入修改訂單的客戶的姓名:"); ?? ??? ?fflush(stdin); ?? ??? ?rewind(stdin); ?? ??? ?gets(nam); ?? ??? ?checkchar1(nam); ?? ??? ?while (strcmp(p->room_->u.name, nam) != 0 && p->onext != NULL) ?? ??? ??? ?p = p->onext; ?? ??? ?if (strcmp(p->room_->u.name, nam) == 0) ?? ??? ?{ ?? ??? ??? ?m++; ?? ??? ??? ?if (Check_date1(p->year, p->mon, p->day, p->hour) != 0) { ?? ??? ??? ??? ?printf("已到入住日期無(wú)法修改"); ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ?? ??? ??? ?else while (1) ?? ??? ??? ?{ ?? ??? ??? ??? ?system("cls"); ?? ??? ??? ??? ?printf("1.修改姓名\n"); ?? ??? ??? ??? ?printf("2.修改電話\n"); ?? ??? ??? ??? ?printf("3.修改身份證號(hào)\n"); ?? ??? ??? ??? ?printf("4.修改入住時(shí)期\n"); ?? ??? ??? ??? ?printf("5.修改離開(kāi)時(shí)期\n"); ?? ??? ??? ??? ?printf("6.退出修改\n"); ?? ??? ??? ??? ?printf("輸入要修改的選項(xiàng):\n"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?gets(num); ?? ??? ??? ??? ?while ((strcmp(num, "1") != 0) && (strcmp(num, "2") != 0) && (strcmp(num, "3") != 0) && (strcmp(num, "4") != 0) && (strcmp(num, "5") != 0) && (strcmp(num, "6") != 0)) { ?? ??? ??? ??? ??? ?printf("選擇有誤,請(qǐng)重新輸入:"); ?? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ?gets(num); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (strcmp(num, "1") == 0) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?printf("輸入新的姓名:"); ?? ??? ??? ??? ??? ?checkchar(p->room_->u.name); ?? ??? ??? ??? ??? ?gets(nam); ?? ??? ??? ??? ??? ?while (strcmp(p->room_->u.name, nam) == 0) { ?? ??? ??? ??? ??? ??? ?printf("姓名未更改,請(qǐng)重新輸入:"); ?? ??? ??? ??? ??? ??? ?scanf("%s", nam); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?checkchar1(nam);//加上換行符才能比較 ?? ??? ??? ??? ??? ?strcpy(p->room_->u.name, nam); ?? ??? ??? ??? ??? ?printf("修改成功\n"); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (strcmp(num, "2") == 0) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?printf("輸入新的電話:"); ?? ??? ??? ??? ??? ?checkchar(p->room_->u.phonenumber); ?? ??? ??? ??? ??? ?scanf("%s", phonenumber_); ?? ??? ??? ??? ??? ?while (strlen(phonenumber_) != 11 || judgephone(phonenumber_) != 0 || strcmp(p->room_->u.phonenumber, phonenumber_) == 0) { ?? ??? ??? ??? ??? ??? ?printf("電話號(hào)不符合要求,請(qǐng)重新輸入:"); ?? ??? ??? ??? ??? ??? ?scanf("%s", phonenumber_); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?checkchar1(phonenumber_);//加上換行符才能比較 ?? ??? ??? ??? ??? ?strcpy(p->room_->u.phonenumber, phonenumber_); ?? ??? ??? ??? ??? ?printf("修改成功\n"); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (strcmp(num, "3") == 0) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?printf("輸入新的身份證號(hào):"); ?? ??? ??? ??? ??? ?checkchar(p->room_->u.idcard); ?? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ?scanf("%s", id); ?? ??? ??? ??? ??? ?while (strlen(id) != 18 || judgeid(id) != 0 || strcmp(p->room_->u.idcard, id) == 0) { ?? ??? ??? ??? ??? ??? ?printf("身份證號(hào)碼格式有誤,請(qǐng)重新輸入:"); ?? ??? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ??? ?scanf("%s", id); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?checkchar1(id);//加上換行符才能比較 ?? ??? ??? ??? ??? ?strcpy(p->room_->u.idcard, id); ?? ??? ??? ??? ??? ?printf("修改成功\n"); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (strcmp(num, "4") == 0) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?if (Check_date1(p->year, p->mon, p->day, p->hour) == 0) { ?? ??? ??? ??? ??? ??? ?printf("請(qǐng)輸入入住時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ??? ?while ((scanf("%d/%d/%d/%d", &p->year[0], &p->mon[0], &p->day[0], &p->hour[0]) != 4) || Check_date1(p->year, p->mon, p->day, p->hour) != 0 || Check_date2(p->year, p->mon, p->day, p->hour) != 0) { ?? ??? ??? ??? ??? ??? ??? ?if (Check_date2(p->year, p->mon, p->day, p->hour) != 0) { ?? ??? ??? ??? ??? ??? ??? ??? ?printf("請(qǐng)修改離開(kāi)時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ??? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ??? ??? ??? ?while ((scanf("%d/%d/%d/%d", &p->year[1], &p->mon[1], &p->day[1], &p->hour[1]) != 4) || Check_date2(p->year, p->mon, p->day, p->hour) != 0) { ?? ??? ??? ??? ??? ??? ??? ??? ??? ?printf("日期輸入有誤,"); ?? ??? ??? ??? ??? ??? ??? ??? ??? ?printf("請(qǐng)重新輸入離開(kāi)時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ??? ??? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ??? ??? ??? ?}break; ?? ??? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ??? ?else { ?? ??? ??? ??? ??? ??? ??? ??? ?printf("日期輸入有誤\n"); ?? ??? ??? ??? ??? ??? ??? ??? ?printf("請(qǐng)重新輸入入住時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ??? ??? ?rewind(stdin);} ?? ??? ??? ??? ??? ??? ?} ? ?? ??? ??? ??? ??? ??? ?printf("修改成功\n"); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (strcmp(num, "5") == 0) { ?? ??? ??? ??? ??? ?printf("請(qǐng)輸入離開(kāi)時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ?while ((scanf("%d/%d/%d/%d", &p->year[1], &p->mon[1], &p->day[1], &p->hour[1]) != 4) || Check_date2(p->year, p->mon, p->day, p->hour) != 0) { ?? ??? ??? ??? ??? ??? ?printf("日期輸入有誤,"); ?? ??? ??? ??? ??? ??? ?printf("請(qǐng)重新輸入離開(kāi)時(shí)間:年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):"); ?? ??? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?printf("修改成功\n"); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (strcmp(num, "6") == 0)break; ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ? ?? ??? ?} ?? ??? ?if (m == 0)printf("該客人不在訂單中\(zhòng)n"); ?? ??? ?printf("\n"); ?? ??? ?system("pause"); ?? ?} } void deleteorder() { ?? ?char nam[20]; ?? ?system("cls"); ?? ?if (ohead->onext == NULL) ?? ?{ ?? ??? ?printf("沒(méi)有可刪除的訂單\n"); ?? ??? ?system("pause"); ?? ?} ?? ?else { ?? ??? ?printf("請(qǐng)輸入你要?jiǎng)h除的訂單的姓名:"); ?? ??? ?fflush(stdin); ?? ??? ?rewind(stdin); ?? ??? ?gets(nam); ?? ??? ?checkchar1(nam);//加上換行符才能比較 ?? ??? ?Order* p; ?? ??? ?Order* q; ?? ??? ?p = ohead; ?? ??? ?q = p->onext; ?? ??? ?while (q != NULL) { ?? ??? ??? ?if (strcmp(q->room_->u.name, nam) == 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?emptyroom(q->room_->roomnumber); ?? ??? ??? ??? ?p->onext = q->onext; ?? ??? ??? ??? ?free(q); ?? ??? ??? ??? ?q = p->onext; ?? ??? ??? ??? ?printf("已刪除該訂單\n"); ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ?? ??? ??? ?else { ?? ??? ??? ??? ?p = p->onext; ?? ??? ??? ??? ?q = q->onext; ?? ??? ??? ?} ? ?? ??? ?} ?? ?} ? } void changeKEY() { ?? ?char s[15], c[15], n[15]; ?? ?int i, a = 0, b = 0, e = 0; ?? ?system("cls"); ? ?? ?FILE* fp = fopen("password.txt", "r+"); ?? ?if (fp == NULL) { ?? ??? ?printf("Failed to open file"); ? ?? ?} ?? ?fgets(s, 14, fp);//取出密碼 ?? ?rewind(fp);//指針回到文件開(kāi)頭 ?? ?fclose(fp); ?? ?fp = fopen("password.txt", "w"); ?? ?printf("請(qǐng)輸入原密碼:\n"); ?? ?fflush(stdin); ?? ?rewind(stdin); ?? ?gets(c); ?? ?while (strcmp(c, s) != 0) { ?? ??? ?printf("原密碼輸入錯(cuò)誤\n請(qǐng)重新輸入"); ?? ??? ?fflush(stdin); ?? ??? ?rewind(stdin); ?? ??? ?gets(c); ?? ?} ?? ?if (strcmp(c, s) == 0) { ?? ??? ?printf("請(qǐng)輸入新密碼(6~14位):\n"); ?? ??? ?fflush(stdin); ?? ??? ?rewind(stdin); ?? ??? ?gets(n); ?? ?} ?? ? ?? ?i = strlen(n); ? ?? ?for (int f = 0; f < i; f++) ?? ?{ ?? ??? ?if (('a' <= n[f] && n[f] <= 'z') || ('A' <= n[f] && n[f] <= 'Z')) ?? ??? ??? ?a++; ?? ??? ?else if ('0' <= n[f] && n[f] <= '9') ?? ??? ??? ?b++; ? ?? ??? ?else ?? ??? ??? ?e++; ?? ?}//判斷字母數(shù)字和其他字符的個(gè)數(shù) ? ?? ?while (i < 6 || i >= 15 || a == 0 || b == 0 || e == 0|| strcmp(n, s) == 0) { ? ?? ??? ?if (strcmp(n, s) == 0)printf("\n與原密碼相同\n請(qǐng)重新輸入:"); ?? ??? ?else printf("\n安全性不高或位數(shù)不符合要求\n請(qǐng)重新輸入:\n"); ?? ??? ?fflush(stdin); ?? ??? ?rewind(stdin); ?? ??? ?gets(n); ?? ??? ?i = strlen(n); ?? ??? ?a = 0; b = 0; e = 0; ?? ??? ?for (int f = 0; f < i; f++) ?? ??? ?{ ?? ??? ??? ?if (('a' <= n[f] && n[f] <= 'z') || ('A' <= n[f] && n[f] <= 'Z')) ?? ??? ??? ??? ?a++; ?? ??? ??? ?else if ('0' <= n[f] && n[f] <= '9') ?? ??? ??? ??? ?b++; ? ?? ??? ??? ?else ?? ??? ??? ??? ?e++; ?? ??? ?} ?? ?}//判斷字母數(shù)字和其他字符的個(gè)數(shù)} ?? ?? ?? ?fputs(n, fp); ?? ?fclose(fp); ?? ?printf("\n密碼修改成功\n"); ?? ?system("pause"); } void color1() { ?? ?char e[15]; ?? ?FILE* fp = fopen("color.txt", "r"); ?? ?if (fp == NULL) { ?? ??? ?printf("Failed to open file"); ? ?? ?} ?? ?e[0] = fgetc(fp); ?? ?fclose(fp); ?? ?switch (*e) { ? ?? ?case'1':system("color 10"); break; ?? ?case'2':system("color 20"); break; ?? ?case'3':system("color 30"); break; ?? ?case'4':system("color 40"); break; ?? ?case'5':system("color 50"); break; ?? ?case'6':system("color 60"); break; ?? ?case'7':system("color 70"); break; ?? ?case'8':system("color 80"); break; ?? ?case'9':system("color 90"); break; ?? ?case'A':system("color A0"); break; ?? ?case'B':system("color B0"); break; ?? ?case'C':system("color C0"); break; ?? ?case'D':system("color D0"); break; ?? ?case'E':system("color E0"); break; ?? ?case'F':system("color F0"); break; ? ?? ?} } void changecolor1() { ?? ?int a; ?? ?system("cls"); ?? ?FILE* p = fopen("color.txt", "w"); ?? ?if (p == NULL) { ?? ??? ?printf("Failed to open file"); ? ?? ?} ? ?? ?printf("顏色列表:1=藍(lán)色 2=綠色 3=湖藍(lán)色 4=紅色\n5=紫色 6=黃色 7=白色 8=灰色\n9=淡藍(lán)色 10=淡綠色 11=淡淺綠色 12=淡紅色\n13=淡紫色 14=淡黃色 15=亮白色\n"); ?? ?printf("請(qǐng)選擇相應(yīng)數(shù)字改變系統(tǒng)顏色"); ? ?? ?scanf("%d", &a); ?? ?while (a < 1 || a>15) { printf("您的輸入有誤,請(qǐng)重新輸入\n"); ?scanf("%d", &a); } ?? ?switch (a) { ? ?? ?case 1:system("color 10"); fputs("1", p); break; ?? ?case 2:system("color 20"); fputs("2", p); break; ?? ?case 3:system("color 30"); fputs("3", p); break; ?? ?case 4:system("color 40"); fputs("4", p); break; ?? ?case 5:system("color 50"); fputs("5", p); break; ?? ?case 6:system("color 60"); fputs("6", p); break; ?? ?case 7:system("color 70"); fputs("7", p); break; ?? ?case 8:system("color 80"); fputs("8", p); break; ?? ?case 9:system("color 90"); fputs("9", p); break; ?? ?case 10:system("color A0"); fputs("A", p); break; ?? ?case 11:system("color B0"); fputs("B", p); break; ?? ?case 12:system("color C0"); fputs("C", p); break; ?? ?case 13:system("color D0"); fputs("D", p); break; ?? ?case 14:system("color E0"); fputs("E", p); break; ?? ?case 15:system("color F0"); fputs("F", p); break; ? ?? ?}fclose(p); printf("\n顏色修改成功\n"); ?? ?system("pause"); ? } void search2() { ?? ?system("cls"); ?? ?Order* p; ?? ?int m; ?? ?if (ohead->onext == NULL) ?? ?{ ?? ??? ?printf("無(wú)訂單,查找失敗\n"); ?? ??? ?system("pause"); ?? ?} ?? ?else ?? ?{ ?? ??? ?while (1) { ?? ??? ??? ?system("cls"); ?? ??? ??? ?printf("選擇查找方式:(1~4)\n"); ?? ??? ??? ?printf("1.按姓名查找\n"); ?? ??? ??? ?printf("2.按電話查找\n"); ?? ??? ??? ?printf("3.按身份證號(hào)查找\n"); ?? ??? ??? ?printf("4.按房間號(hào)查找\n"); ?? ??? ??? ?printf("5.返回上一層\n"); ?? ??? ??? ?char t[20]; ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?gets(t); ?? ??? ??? ?while ((strcmp(t, "1") != 0) && (strcmp(t, "2") != 0) && (strcmp(t, "3") != 0) && (strcmp(t, "4") != 0) && (strcmp(t, "5") != 0)) { ?? ??? ??? ??? ?printf("選擇有誤,請(qǐng)重新輸入:"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?gets(t); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(t, "1") == 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?m = 0; ?? ??? ??? ??? ?p = ohead->onext; ?? ??? ??? ??? ?printf("輸入查找的姓名:"); ?? ??? ??? ??? ?char nam[40]; ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?gets(nam); ?? ??? ??? ??? ?while (p != NULL) ?? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ?checkchar(p->room_->u.name); ?? ??? ??? ??? ??? ?if (FindSubstring(p->room_->u.name, nam) == 0) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?m++; ?? ??? ??? ??? ??? ??? ?checkchar1(p->room_->u.name); ?? ??? ??? ??? ??? ??? ?printf("\n姓名:%s\n", p->room_->u.name); ?? ??? ??? ??? ??? ??? ?printf("\n電話:%s\n", p->room_->u.phonenumber); ?? ??? ??? ??? ??? ??? ?printf("身份證號(hào):%s\n", p->room_->u.idcard); ?? ??? ??? ??? ??? ??? ?printf("房間號(hào): %s\n", p->room_->roomnumber); ?? ??? ??? ??? ??? ??? ?printf("入住日期:%d/%d/%d/%d\n", p->year[0], p->mon[0], p->day[0], p->hour[0]); ?? ??? ??? ??? ??? ??? ?printf("離開(kāi)日期:%d/%d/%d/%d\n", p->year[1], p->mon[1], p->day[1], p->hour[1]); ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?p = p->onext; ?? ??? ??? ??? ?} ? ?? ??? ??? ??? ?if (m == 0) ?? ??? ??? ??? ??? ?printf("查找用戶不存在\n"); ?? ??? ??? ??? ?system("pause"); ? ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(t, "2") == 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?m = 0; ?? ??? ??? ??? ?p = ohead->onext; ?? ??? ??? ??? ?char ph[20]; ?? ??? ??? ??? ?printf("輸入查找的電話:"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?gets(ph); ?? ??? ??? ??? ?while (strlen(ph) != 11 || judgephone(ph) != 0) ?? ??? ??? ??? ?{//判斷電話號(hào)號(hào)是否符合規(guī)則。 ?? ??? ??? ??? ??? ?printf("電話號(hào)不符合要求,請(qǐng)重新輸入:"); ?? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ?scanf("%s", ph); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?checkchar1(ph); ?? ??? ??? ??? ?while (p != NULL && strcmp(ph, p->room_->u.phonenumber) == 0) { ?? ??? ??? ??? ??? ?//找到電話一致的客人 ?? ??? ??? ??? ??? ?if (strcmp(ph, p->room_->u.phonenumber) == 0) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?m++; ?? ??? ??? ??? ??? ??? ?printf("\n姓名:%s\n", p->room_->u.name); ?? ??? ??? ??? ??? ??? ?printf("\n電話:%s\n", p->room_->u.phonenumber); ?? ??? ??? ??? ??? ??? ?printf("身份證號(hào):%s\n", p->room_->u.idcard); ?? ??? ??? ??? ??? ??? ?printf("房間號(hào): %s\n", p->room_->roomnumber); ?? ??? ??? ??? ??? ??? ?printf("入住日期:%d/%d/%d/%d\n", p->year[0], p->mon[0], p->day[0], p->hour[0]); ?? ??? ??? ??? ??? ??? ?printf("離開(kāi)日期:%d/%d/%d/%d\n", p->year[1], p->mon[1], p->day[1], p->hour[1]); ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?p = p->onext; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (m == 0) ?? ??? ??? ??? ??? ?printf("查找號(hào)碼不存在\n"); ?? ??? ??? ??? ?system("pause"); ? ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(t, "3") == 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?char id[18]; ?? ??? ??? ??? ?printf("輸入要查找的身份證號(hào):"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?gets(id); ?? ??? ??? ??? ?while (strlen(id) != 18 || judgeid(id) != 0) {//判斷身份證號(hào)是否符合規(guī)則。 ?? ??? ??? ??? ??? ?printf("身份證號(hào)碼格式有誤,請(qǐng)重新輸入:"); ?? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ?scanf("%s", id); ?? ??? ??? ??? ?} ?? ??? ??? ??? ?checkchar1(id); ?? ??? ??? ??? ?m = 0; ?? ??? ??? ??? ?p = ohead->onext; ?? ??? ??? ??? ?while (p != NULL && strcmp(p->room_->u.idcard, id) == 0) { ?? ??? ??? ??? ??? ?if (strcmp(p->room_->u.idcard, id) == 0) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?m++; ?? ??? ??? ??? ??? ??? ?printf("\n姓名:%s\n", p->room_->u.name); ?? ??? ??? ??? ??? ??? ?printf("\n電話:%s\n", p->room_->u.phonenumber); ?? ??? ??? ??? ??? ??? ?printf("身份證號(hào):%s\n", p->room_->u.idcard); ?? ??? ??? ??? ??? ??? ?printf("房間號(hào): %s\n", p->room_->roomnumber); ?? ??? ??? ??? ??? ??? ?printf("入住日期:%d/%d/%d/%d\n", p->year[0], p->mon[0], p->day[0], p->hour[0]); ?? ??? ??? ??? ??? ??? ?printf("離開(kāi)日期:%d/%d/%d/%d\n", p->year[1], p->mon[1], p->day[1], p->hour[1]); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?p = p->onext; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (m == 0) ?? ??? ??? ??? ??? ?printf("查找號(hào)碼不存在\n"); ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(t, "4") == 0) ?? ??? ??? ?{ ?? ??? ??? ??? ?char roomnum[20]; ?? ??? ??? ??? ?printf("輸入要查找的房間號(hào)(本酒店房間號(hào)101~112;201~208;301~304;401~403):"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?gets(roomnum); ?? ??? ??? ??? ?checkchar1(roomnum); ?? ??? ??? ??? ?m = 0; ?? ??? ??? ??? ?p = ohead->onext; ?? ??? ??? ??? ?while (p != NULL) { ? ?? ??? ??? ??? ??? ?if (strcmp(p->room_->roomnumber, roomnum) == 0) ?? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ?m++; ?? ??? ??? ??? ??? ??? ?printf("\n姓名:%s\n", p->room_->u.name); ?? ??? ??? ??? ??? ??? ?printf("\n電話:%s\n", p->room_->u.phonenumber); ?? ??? ??? ??? ??? ??? ?printf("身份證號(hào):%s\n", p->room_->u.idcard); ?? ??? ??? ??? ??? ??? ?printf("房間號(hào): %s\n", p->room_->roomnumber); ?? ??? ??? ??? ??? ??? ?printf("入住日期:%d/%d/%d/%d\n", p->year[0], p->mon[0], p->day[0], p->hour[0]); ?? ??? ??? ??? ??? ??? ?printf("離開(kāi)日期:%d/%d/%d/%d\n", p->year[1], p->mon[1], p->day[1], p->hour[1]); ? ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?p = p->onext; ? ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (m == 0) ?? ??? ??? ??? ??? ?printf("房間未被使用或未輸入正確房間號(hào)\n"); ?? ??? ??? ??? ?system("pause"); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(t, "5") == 0)break; ?? ??? ??? ?printf("\n"); ?? ??? ?} ?? ?} } void search1() { ?? ?int flag1 = 0, flag2 = 0; ?? ?system("cls"); ?? ?int count1 = 0, count2 = 0, count3 = 0, count4 = 0, m; ?? ?char c[10]; ?? ?Room* p; ?? ?if (rhead->rnext == NULL) ?? ?{ ?? ??? ?printf("無(wú)房間,查找失敗\n"); ?? ??? ?system("pause"); ?? ?} ?? ?else ?? ?{ ?? ??? ?while (1) { ?? ??? ??? ?system("cls"); ?? ??? ??? ?printf("請(qǐng)輸入查詢方式:\n"); ?? ??? ??? ?printf("1.房間狀態(tài)查詢\n"); ?? ??? ?? ?? ??? ??? ?printf("2.房間狀態(tài)和房間類型組合查詢\n"); ?? ??? ??? ?printf("3.返回上一層\n"); ?? ??? ??? ?char t[20]; ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ??? ?gets(t); ?? ??? ??? ?while ((strcmp(t, "1") != 0) && (strcmp(t, "2") != 0) && (strcmp(t, "3") != 0)) { ?? ??? ??? ??? ?printf("選擇有誤,請(qǐng)重新輸入:"); ?? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ?gets(t); ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(t, "1") == 0) { ?? ??? ??? ??? ?system("cls"); ?? ??? ??? ??? ?printf("閑置房:"); ?? ??? ??? ??? ?printf("\n"); ?? ??? ??? ??? ?for (p = rhead->rnext; p->rnext != NULL; p = p->rnext)if (p->flag == 0) { ?? ??? ??? ??? ??? ?printf("%s", p->roomnumber); flag1++; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?printf("\n"); ?? ??? ??? ??? ?if (flag1 == 0)printf("無(wú)"); ?? ??? ??? ??? ?printf("被占用房"); ?? ??? ??? ??? ?printf("\n"); ?? ??? ??? ??? ?for (p = rhead->rnext; p->rnext != NULL; p = p->rnext)if (p->flag != 0) { ?? ??? ??? ??? ??? ?printf("%s", p->roomnumber); flag2++; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?if (flag2 == 0)printf("無(wú)"); ?? ??? ??? ??? ?printf("\n"); ?? ??? ??? ?} ?? ??? ??? ?? ?? ??? ??? ? ?? ??? ??? ?if (strcmp(t, "2") == 0) { ?? ??? ??? ??? ?while (1) { ?? ??? ??? ??? ??? ?system("cls"); ?? ??? ??? ??? ??? ?char n[20]; ?? ??? ??? ??? ??? ?printf("請(qǐng)選擇查詢類型:\n1.單人間\n2.雙人間\n3.三人間\n4.四人間\n5.返回上一層\n"); ?? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ?gets(n); ? ?? ??? ??? ??? ??? ?while (strcmp(n, "1") != 0 && strcmp(n, "2") != 0 && strcmp(n, "3") != 0 && strcmp(n, "4") != 0 && strcmp(n, "5") != 0) { ?? ??? ??? ??? ??? ??? ?printf("選擇有誤,請(qǐng)重新選擇:"); ?? ??? ??? ??? ??? ??? ?fflush(stdin); ?? ??? ??? ??? ??? ??? ?rewind(stdin); ?? ??? ??? ??? ??? ??? ?gets(n); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?if (strcmp(n, "1") == 0) { ?? ??? ??? ??? ??? ??? ?printf("空房有:\n"); ?? ??? ??? ??? ??? ??? ?for (p = rhead->rnext; p != NULL; p = p->rnext) ?? ??? ??? ??? ??? ??? ??? ?if (p->flag == 0 && strcmp(p->type, "single\n") == 0) ?? ??? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ??? ??? ?count1++; printf("%s", p->roomnumber); ?? ??? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?printf("\n"); ?? ??? ??? ??? ??? ??? ?printf("單人間還剩%d間", count1); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?if (strcmp(n, "2") == 0) { ?? ??? ??? ??? ??? ??? ?printf("空房有:\n"); ?? ??? ??? ??? ??? ??? ?for (p = rhead->rnext; p != NULL; p = p->rnext)if (p->flag == 0 && strcmp(p->type, "double\n") == 0) ?? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ??? ?count2++; printf("%s", p->roomnumber); ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?printf("\n"); ?? ??? ??? ??? ??? ??? ?printf("雙人間還剩%d間", count2); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?if (strcmp(n, "3") == 0) { ?? ??? ??? ??? ??? ??? ?printf("空房有:\n"); ?? ??? ??? ??? ??? ??? ?for (p = rhead->rnext; p != NULL; p = p->rnext)if (p->flag == 0 && strcmp(p->type, "triple\n") == 0) ?? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ??? ?count3++; printf("%s", p->roomnumber); ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?printf("三人間還剩%d間", count3); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?if (strcmp(n, "4") == 0) { ?? ??? ??? ??? ??? ??? ?printf("空房有:\n"); ?? ??? ??? ??? ??? ??? ?for (p = rhead->rnext; p != NULL; p = p->rnext)if (p->flag == 0 && strcmp(p->type, "four\n") == 0) ?? ??? ??? ??? ??? ??? ?{ ?? ??? ??? ??? ??? ??? ??? ?count4++; printf("%s", p->roomnumber); ?? ??? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ??? ?printf("\n"); ?? ??? ??? ??? ??? ??? ?printf("四人間還剩%d間", count4); ?? ??? ??? ??? ??? ?} ?? ??? ??? ??? ??? ?if (strcmp(n, "5") == 0)break; ?? ??? ??? ??? ??? ?printf("\n"); ?? ??? ??? ??? ??? ?system("pause"); ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ??? ?if (strcmp(t, "3") == 0)break; ?? ??? ??? ?printf("\n"); ?? ??? ??? ?system("pause"); ?? ??? ?} ? ?? ?} } void statistics() { ?? ?system("cls"); ? ?? ?Order* e; int m, year, mon, day, hour; ?? ?if (ohead->onext == NULL) ?? ?{ ?? ??? ?printf("無(wú)訂單\n"); ?? ??? ?system("pause"); ?? ?} ?? ?else { ?? ??? ?printf("請(qǐng)輸入截止日期 年月日時(shí)(24時(shí))中間請(qǐng)用/隔開(kāi):\n"); ?? ??? ?fflush(stdin); ?? ??? ?rewind(stdin); ? ?? ??? ?while ((scanf("%d/%d/%d/%d", &year, &mon, &day, &hour)) != 4 || Check_date4(year, mon, day, hour) == 1) ?? ??? ?{ ?? ??? ??? ?printf("請(qǐng)輸入有效時(shí)間"); ?? ??? ??? ?fflush(stdin); ?? ??? ??? ?rewind(stdin); ?? ??? ?} ?? ??? ?printf("在該日期前生效的訂單有\(zhòng)n"); ?? ??? ?for (e = ohead->onext; e != NULL; e = e->onext)if (time_1(year, mon, day, hour, e) == -1 || time_1(year, mon, day, hour, e) == 0) { ?? ??? ??? ?printf("\n姓名:%s", e->room_->u.name); ?? ??? ??? ?printf("電話:%s", e->room_->u.phonenumber); ?? ??? ??? ?printf("身份證號(hào):%s", e->room_->u.idcard); ?? ??? ??? ?printf("房間號(hào): %s", e->room_->roomnumber); ?? ??? ??? ?printf("入住日期:%d/%d/%d/%d\n", e->year[0], e->mon[0], e->day[0], e->hour[0]); ?? ??? ??? ?printf("離開(kāi)日期:%d/%d/%d/%d\n", e->year[1],e->mon[1], e->day[1], e->hour[1]); ?? ??? ??? ?printf("\n"); ?? ??? ?} ?? ?} ?? ?system("pause"); } int time_1(int year, int mon, int day, int hour, Order* p) { ? ?? ?if ((p->year[0]) > year)return 1; ?? ?if ((p->year[0]) < year)return -1; ?? ?if ((p->year[0]) == year) { ?? ??? ?if ((p->mon[0]) > mon)return 1; ?? ??? ?if ((p->mon[0]) < mon)return -1; ?? ??? ?if ((p->mon[0]) == mon) { ?? ??? ??? ?if ((p->day[0]) < day)return -1; ?? ??? ??? ?if ((p->day[0]) > day)return ?1; ?? ??? ??? ?if ((p->day[0]) == day) { ?? ??? ??? ??? ?if ((p->hour[0]) < hour)return -1; ?? ??? ??? ??? ?if ((p->hour[0]) > hour)return 1; ?? ??? ??? ??? ?if ((p->hour[0]) == hour)return 0; ?? ??? ??? ?} ?? ??? ?} ?? ?} } void read_() { ?? ?? ?? ?extern Room* rhead; ?? ?extern Order* ohead; ?? ?FILE* fp = NULL; ?? ?FILE* fp1 = NULL; ?? ?char ch; ?? ?rhead = (Room*)malloc(sizeof(Room)); ?? ?if (rhead != NULL) ?? ?{ ?? ??? ?rhead->rnext = NULL; ?? ?} ?? ?ohead = exploitorderhead(); ?? ?Room* p = rhead; ?? ?Room* q = rhead; ?? ?Order* p1 = ohead; ?? ?Order* q1 = ohead; ?? ?Room* u; ?? ?if ((fp = fopen("room.txt", "r+")) == NULL || (fp1 = fopen("order.txt", "r+")) == NULL) ?? ?{ ?? ??? ?? ?? ??? ?fp = fopen("room1.txt", "r+"); ?? ??? ?fp1 = fopen("order1.txt", "r+"); ?? ?} ?? ?else { ?? ??? ?fp = fopen("room.txt", "r+"); ?? ??? ?fp1 = fopen("order.txt", "r+"); ?? ??? ?? ?? ?} ?? ?while (!feof(fp)) ?? ?{ ?? ??? ?p = (Room*)malloc(sizeof(Room)); ?? ??? ?fgets(p->roomnumber, 20, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ?//printf("%s\n",p->roomnumber); ?? ??? ?fgets(p->type, 20, fp);//讀進(jìn)來(lái)的還有換行符 ?? ??? ?//printf("%s\n",p->type); ?? ??? ?fscanf(fp, "%d", &(p->flag)); ?? ??? ?//printf("%d\n",p->flag); ?? ??? ?ch = fgetc(fp); ?? ??? ?ch = fgetc(fp); ?? ??? ?q->rnext = p; ?? ??? ?q = p; ?? ?} ?? ?q->rnext = NULL; ?? ?fclose(fp); ?? ?ch = fgetc(fp1); ?? ?if (!feof(fp1)) { ?? ??? ?rewind(fp1); ?? ??? ?while (!feof(fp1)) ?? ??? ?{ ?? ??? ??? ?p1 = (Order*)malloc(sizeof(Order)); ?? ??? ??? ?u = (Room*)malloc(sizeof(Room)); ?? ??? ??? ?p1->room_ = u; ?? ??? ??? ?fgets(p1->room_->roomnumber, 40, fp1);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p1->room_->type, 10, fp1);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p1->room_->u.name, 40, fp1);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p1->room_->u.idcard, 20, fp1);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fgets(p1->room_->u.phonenumber, 20, fp1);//讀進(jìn)來(lái)的還有換行符 ?? ??? ??? ?fscanf(fp1, "%d/%d/%d/%d", &p1->year[0], &p1->mon[0], &p1->day[0], &p1->hour[0]); ?? ??? ??? ?ch = fgetc(fp1); ?? ??? ??? ?fscanf(fp1, "%d/%d/%d/%d", &p1->year[1], &p1->mon[1], &p1->day[1], &p1->hour[1]); ?? ??? ??? ?ch = fgetc(fp1); ?? ??? ??? ?ch = fgetc(fp1); ?? ??? ??? ?q1->onext = p1; ?? ??? ??? ?q1 = p1; ?? ??? ?} ?? ?} ?? ?q1->onext = NULL; ?? ?fclose(fp1); ?? ?deletedisabledorder(); ?? ?? } void backups() { ?? ?system("cls"); ?? ?FILE* fp = NULL; ?? ?FILE* fp1 = NULL; ?? ?if ((fp = fopen("order1.txt", "w")) == NULL) ?? ?{ ?? ??? ?printf("can't built the order1 file\n"); ?? ??? ?system("pause"); ?? ?} ?? ?if ((fp1 = fopen("room1.txt", "w")) == NULL) ?? ?{ ?? ??? ?printf("can't open the room1 file\n"); ?? ??? ?system("pause"); ?? ?} ?? ?Room* p1 = rhead->rnext; ?? ?Order* p = ohead->onext; ?? ?while (p != NULL) { ?? ??? ?fputs(p->room_->roomnumber, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->type, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->u.name, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->u.idcard, fp);//連換行符一起保存 ?? ??? ?fputs(p->room_->u.phonenumber, fp);//連換行符一起保存 ?? ??? ?fprintf(fp, "%d", p->year[0]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->mon[0]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->day[0]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->hour[0]); ?? ??? ?fputc('\n', fp); ?? ??? ?fprintf(fp, "%d", p->year[1]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->mon[1]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->day[1]); ?? ??? ?fputc('/', fp); ?? ??? ?fprintf(fp, "%d", p->hour[1]); ?? ??? ?fputc('\n', fp); ?? ??? ?if (p->onext != NULL)fputc('\n', fp); ?? ??? ?p = p->onext; ?? ?} ?? ?while (p1 != NULL) { ?? ??? ?fputs(p1->roomnumber, fp1); ?? ??? ?fputs(p1->type, fp1); ?? ??? ?fprintf(fp1, "%d", p1->flag); ?? ??? ?fputc('\n', fp1); ?? ??? ?if (p1->rnext != NULL)fputc('\n', fp1); ?? ??? ?p1 = p1->rnext; ?? ?} ?? ?if (fclose(fp1) == 0 && fclose(fp) == 0)printf("備份成功\n"); ?? ?else ?? ??? ?printf("備份失敗\n"); ?? ?system("pause"); } int FindSubstring(const char* strSource, const char* strSub) { ?? ?unsigned int uLen = strlen(strSource); ?? ?if (uLen == 0) ?? ?{ ?? ??? ?return -1; ?? ?} ?? ?char* str1 = (char*)malloc(uLen + 1); ?? ?memset(str1, '\0', uLen + 1); ?? ?strcpy(str1, strSource); ?? ?uLen = strlen(strSub); ?? ?if (uLen == 0) ?? ?{ ?? ??? ?free(str1); ?? ??? ?return -1; ?? ?} ?? ?char* str2 = (char*)malloc(uLen + 1); ?? ?memset(str2, '\0', uLen + 1); ?? ?strcpy(str2, strSub); ?? ?unsigned int i = 0, j = 0; ?? ?for (i = 0; i < strlen(strSource); i = i + 2) ?? ?{ ?? ??? ?if (str1[i] == str2[j] && str1[i + 1] == str2[j + 1]) ?? ??? ?{ ?? ??? ??? ?j++; ?? ??? ??? ?j++; ?? ??? ?} ?? ??? ?else ?? ??? ?{ ?? ??? ??? ?if (j == uLen) ?? ??? ??? ?{ ?? ??? ??? ??? ?break; ?? ??? ??? ?} ?? ??? ??? ?else ?? ??? ??? ?{ ?? ??? ??? ??? ?j = 0; ?? ??? ??? ?} ?? ??? ?} ?? ?} ?? ?free(str1); ?? ?free(str2); ?? ?if (j == uLen) ?? ?{ ?? ??? ?return 0; ?? ?} ?? ?else ?? ?{ ?? ??? ?return -1; ?? ?} }
main.c
#include <stdio.h> #include "function.h" #include "struct.h" Room* rhead; Order* ohead; int main() { ?? ?registers(); }
此外,程序的正確運(yùn)行還需項(xiàng)目文件夾下包括下圖所示的文本文件
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++&&Opencv實(shí)現(xiàn)控制臺(tái)字符動(dòng)畫(huà)的方法
這篇文章主要介紹了C++&&Opencv實(shí)現(xiàn)控制臺(tái)字符動(dòng)畫(huà)的方法,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07C語(yǔ)言實(shí)現(xiàn)簡(jiǎn)單圖書(shū)管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)圖書(shū)管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01C語(yǔ)言實(shí)現(xiàn)猜數(shù)字游戲
這篇文章主要為大家詳細(xì)介紹了C語(yǔ)言實(shí)現(xiàn)猜數(shù)字游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-11-11Qt 鼠標(biāo)/觸屏繪制平滑曲線(支持矢量/非矢量方式)
這篇文章主要介紹了Qt 鼠標(biāo)/觸屏繪制平滑曲線(支持矢量/非矢量方式),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04淺談c++性能測(cè)試工具之計(jì)算時(shí)間復(fù)雜度
有時(shí)候除了測(cè)量算法的具體性能指數(shù),我們也會(huì)希望測(cè)試出算法的時(shí)間復(fù)雜度,以便我們對(duì)待測(cè)試的算法的性能有一個(gè)更加直觀的了解。本文將介紹c++性能測(cè)試工具之計(jì)算時(shí)間復(fù)雜度。2021-06-06