简易酒店管理系统代码

更新时间:2024-06-23 01:30:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

#include #include #include #include

//时间函数的定义

struct tm *localtime(const time_t * timep);

//时间的初始化

char *wday[]={\星期天\星期一\星期二\星期三\星期四\星期五\星期六\ time_t timep; struct tm *now; struct tm *after; // time(&timep);

//酒店房间的定义 struct house { char house_number[10]; char house_shape[2]; float house_price; int sum_person; // struct house *next; }h[10]= { {\ {\ {\ {\ {\ {\ {\ {\ {\ {\};

struct guest { //住客姓名、性别、年龄、身份、身份证号码,房号,床号,入住日期、入住时间、离店日期、离店时间。 char name[10]; char sex[6]; int age; char identify[18]; char identify_number[18]; char room[10]; char bed[10]; // Date guest_in; // Date guest_out; struct tm *p; struct tm *q; struct guest *next; };

void first_inquiry() { int i=0; int n=0; char ch[2]=\ for (i=0;i<10;i++) { if ((strcmp(h[i].house_shape,ch)==0)) { if (h[i].sum_person==0) { printf(\ } } } }

void second_inquiry() { { int i=0; int n=0; char ch[2]=\

for (i=0;i<10;i++) { if ((strcmp(h[i].house_shape,ch)==0)) { if (h[i].sum_person==0) { printf(\ } } } } }

void third_inquiry() { int i=0; int n=0; char ch[2]=\ for (i=0;i<10;i++) { if ((strcmp(h[i].house_shape,ch)==0)) { if (h[i].sum_person==0) { printf(\ } } } }

void lookfor_house_is_Null() { int your_choice; do { printf(\你要查询:1.单人间 2.双人间 3.多人间 4.退出:\\n\ printf(\输入你的选择:\\t\

scanf(\ switch(your_choice) { case 1: printf(\单人间的空余房间:\\t\ first_inquiry(); printf(\ break; case 2: printf(\双人房的空余房间:\\t\ second_inquiry(); printf(\ break; case 3: printf(\多人间的空余房间:\\t\ third_inquiry(); printf(\ break; case 4: // exit(1); break; } } while(your_choice!=4); printf(\ printf(\ }

void add_house_sum_number(char str[10]) { int i=0; for (i=0;i<10;i++) { if ((strcmp(h[i].house_number,str)==0)) {

h[i].sum_person=1; } else { continue; } } }

typedef struct guest * link_guest;

//创建

link_guest create_guest(void) { link_guest head=(link_guest)malloc(sizeof(struct guest)); if (head!=NULL) { head->next=NULL; } else { printf(\ } return head; }

bool is_null_guest(link_guest head) { if(head->next==NULL) { return true; } return false; }

//写个函数判断一下 当输入住客的房号时,是否还有个这个房间 bool is_null_this_house(char str[10]) { int i=0;

for (i=0;i<10;i++) { if ((strcmp(h[i].house_number,str)==0)) { // ; if (h[i].sum_person==0) { return true; } else { printf(\该房间已经有人住了!\\n\ //continue; return false; } } } return false; }

//打印一下 刚输进住客的信息

void printf_detail_now(link_guest p) { printf(\ printf(\住客姓名: \\t%s\\n\ printf(\性别: \\t%s\\n\ printf(\年龄: \\t%d\\n\ printf(\身份: \\t%s\\n\ printf(\身份证号码: \\t%s\\n\ printf(\房号: \\t%s\\n\ printf(\床号: \\t%s\\n\ printf(\该住客入住的时间:\\t\ printf (\年%d月%d日 %s \(1900+p->p->tm_year),(1+p->p->tm_mon), p->p->tm_mday,wday[p->p->tm_wday]);

printf(\ //printf(\ }

//输入住客的信息

link_guest insert_guest(link_guest head) { link_guest p,ptr; int n=0; bool flag=false; p=(link_guest)malloc(sizeof(struct guest)); p->next=NULL; ptr=(link_guest)malloc(sizeof(struct guest)); ptr->next=NULL; scanf(\ber,&p->room,&p->bed); printf(\ printf(\请按详细填写住客的信息:\\n\ printf(\请输入住客姓名:\\t\\t\ scanf(\ printf(\请输入性别:\\t\\t\ scanf(\ printf(\请输入年龄:\\t\\t\ scanf(\ printf(\请输入身份:\\t\\t\ scanf(\

printf(\请输入身份证号码:\\t\scanf(\

printf(\住客可以住在:\\n\printf(\单人间(200元/天):\\n\printf(\first_inquiry();

printf(\双人间(150元/天):\\n\printf(\

second_inquiry();

printf(\多人间(100元/天):\\n\printf(\third_inquiry(); printf(\ do { printf(\请输入房号:\\t\\t\ scanf(\ flag=is_null_this_house(p->room); add_house_sum_number(p->room); } while(flag!=true);

//写个对于不同房间的判断函数,便于选择床位; /*printf(\住客可以选择的床号:\\t\

printf(\请输入床号:\\t\\t\

//这里写个函数,如果是多人间的,要列出可以选择的床号

scanf(\

printf(\该住客入住的时间:\\t\

p->p=NULL; // 时间函数这里用得不正确,就是输入下一个住客的入住时间时,并没有正确的显示 time(&timep); //p->p=localtime(&timep); p->p=gmtime(&timep); printf (\年%d月%d日 %s \(1900+p->p->tm_year),(1+p->p->tm_mon), p->p->tm_mday,wday[p->p->tm_wday]);

printf(\ if (is_null_guest(head)) { head->next=p; p->next=NULL; } else { ptr=head; while(ptr->next!=NULL) { ptr=ptr->next; } ptr->next=p; p->next=NULL; } printf(\该住客的信息已经登记好!\\n\ printf(\ printf(\刚登记的住客的信息:\\n\ printf_detail_now(p);

printf(\ return head; }

link_guest lookfor_guest_house_number(link_guest p) { char house_number[10]; bool flag=false; printf(\输入你要查找的住客的房号:\\t\ scanf(\ while (p!=NULL) { if ((strcmp(p->room,house_number))==0) { flag=true; break; } p=p->next; } if (flag) { return p; } else { printf(\找不到该客户的信息!\\n\ return NULL; } }

link_guest lookfor_guest_name(link_guest p) { char name[10]; bool flag=false; printf(\输入你要查找的住客的姓名:\\t\ scanf(\ while (p!=NULL) { if ((strcmp(p->name,name))==0) { flag=true; break; } p=p->next; } if (flag) { return p; } else { printf(\找不到该客户的信息!\\n\ return NULL; } }

void printf_detail(link_guest p,bool flag) { if (flag==true) { printf(\

printf(\住客姓名: %s\\n\ printf(\性别: %s\\n\ printf(\年龄: %d\\n\ printf(\身份: %s\\n\ printf(\身份证号码: %s\\n\ printf(\房号: %s\\n\ printf(\床号: %s\\n\ printf(\入住时间: \ printf(\年%d月%d日 %s \(1900+p->p->tm_year),(1+p->p->tm_mon), p->p->tm_mday,wday[p->p->tm_wday]); printf(\ printf(\ } }

//查找住客的信息

//5.能查询(查找)一些基本信息(如按房号查询、按姓名查询、空余客房查询等);

bool is_null(link_guest p) { if (p==NULL) { return false; } else { return true; } }

//按房间价格排序

void price_order() { int i=0; int j=0; float price=200.0; printf(\

printf(\单人间200.0元/天:\\n\ printf(\房间号为:\\t\ for (i=0;i<10;i++) { if (h[i].house_price==price) { printf(\ } } printf(\ printf(\ price=150.0; printf(\双人间150.0元/天:\\n\ printf(\房间号为:\\t\ for (i=0;i<10;i++) { if (h[i].house_price==price) { printf(\ } } printf(\ printf(\ price=200.0; printf(\多人间100.0元/天:\\n\ printf(\房间号为:\\t\ for (i=0;i<10;i++) { if (h[i].house_price==price) { printf(\ } } printf(\ printf(\ }

//查询所有客房的信息

void printf_all_house() { int i=0; int choice; do { printf(\按价格排序 2.按空房查询 3.退出:\\n\ printf(\你的选择:\\t\ scanf(\ switch(choice) { case 1: printf(\ price_order(); break; case 2: printf(\ lookfor_house_is_Null(); break; case 3: break; default: printf(\没有这个选择!\\n\ break; } } while(choice!=3); }

void lookfor_guest(link_guest head) { //char name[10]; // char ch; //char yes=y;

bool flag=false;

bool isNull=false;

int choice;

if (is_null_guest(head)) { printf(\当前没有任何住客的信息!\\n\ return ; }

link_guest p,q;

q=head->next; do { p=q; printf(\按房号查询 2.按姓名查询 3.空余客房查询 4.退出查询\\n\\n\ printf(\输入你的选择:\\t\ scanf(\ printf(\ switch(choice) { case 1: p=lookfor_guest_house_number(p); isNull=is_null(p); printf_detail(p,isNull); break; case 2: p=lookfor_guest_name(p); isNull=is_null(p);

printf_detail(p,isNull); break; case 3: lookfor_house_is_Null(); // lookfor_guest_isNull_house(p); break; case 4: break; default: break; } } while(choice!=4); }

//删除房间

void delete_house(link_guest p) { int i=0; for (i=0;i<10;i++) { if((strcmp(p->room,h[i].house_number)==0)) { h[i].sum_person=0; } } }

//删除住客的信息

link_guest delete_guest(link_guest head) { link_guest p,q;

char name[10];

p=head;

if (is_null_guest(p)) { printf(\ printf(\没有任何住客的信息!\\n\ printf(\ return head; } else { printf(\ printf(\输入你想要删除客户的名字:\\t\ scanf(\ printf(\ while (p->next!=NULL&&(strcmp(p->next->name,name)!=0)) { p=p->next; } if (p->next==NULL) { printf(\找不到该住客的信息!\\n\ return head; } else { q=p->next; p->next=q->next; delete_house(q); free(q); //////////////////////////////////////////////////////////// //写个函数来对这个人住的房间进行删除

printf(\该住客的信息已经删除!\\n\ printf(\ return head; } } return head; }

//对住客的信息进行修改

link_guest modify_guest(link_guest head) { link_guest p; int choice; char name[10]; char sex[6]; int age; char identify[18]; char identify_number[18]; char room[10]; char bed[10]; p=head; if (is_null_guest(p)) { printf(\当前没有任何住客的信息!\\n\ return head; } else { printf(\输入你想要修改客户的名字:\\t\ scanf(\ while (p->next!=NULL&&(strcmp(p->next->name,name)!=0)) { p=p->next;

}

if (p->next==NULL) { printf(\ printf(\没有该住客的信息!\\n\ printf(\ return head; } else { p=p->next; printf(\ printf(\输入你要修改该住客的哪些信息:\\n\ printf(\名字 2.性别 3.年龄 4.身份 5.身份证号码 6.房号 7.床号\\n\ scanf(\ switch(choice) { case 1: printf(\输入你要修改的名字:\\t\\t\ scanf(\ strcpy(p->name,name); break; case 2: printf(\输入你要修改的性别:\\t\\t\ scanf(\ strcpy(p->sex,sex); break; case 3: printf(\输入你要修改的年龄:\\t\\t\ scanf(\ p->age=age; break; case 4:

printf(\输入你要修改的身份:\\t\\t\ scanf(\ strcpy(p->identify,identify); break; case 5: printf(\输入你要修改的身份证号码:\\t\\t\ scanf(\ strcpy(p->identify_number,identify_number); break; case 6: printf(\输入你要修改的房号:\\t\\t\ scanf(\ strcpy(p->room,room); break; case 7: printf(\输入你要修改的床号:\\t\\t\ scanf(\ strcpy(p->bed,bed); break; default: break; } return head; } } return head; }

void printf_guest(link_guest head) { link_guest p; p=head->next; int i=0; if (p==NULL) {

printf(\没有住客的信息.\\n\ return ; } else { for (p; p; p=p->next) { i++; } printf(\已经有%d名住客.\\n\ printf(\ //还没写好 对于不同的房型的情况 } }

//还要写一个函数判断住客住的房间是什么类型的,这样才能确定房间的价钱,才能算出价钱

float the_house_money(link_guest p) { //float money; int i=0; for (i=0;i<10;i++) { if (strcmp(p->room,h[i].house_number)==0) { return h[i].house_price; } } return 0; }

//算出住客应该付多少钱

float pay_for_house_money(struct tm *pstr,link_guest p) { float money; int year;

int month; int day; year=(pstr->tm_year)-(p->p->tm_year); month=(pstr->tm_mon)-(p->p->tm_mon); day=(pstr->tm_mday)-(p->p->tm_mday); day=year*365+month*30+day; if (day<1) { day=1; } money=the_house_money(p); money=day*money; return money; }

//结账的时间

tm *pay_for_time() { time_t timep; //struct tm *p; struct tm *pstr; time(&timep); pstr=gmtime(&timep); printf(\年%d月%d日 %s \(1+pstr->tm_mon), pstr->tm_mday, wday[pstr->tm_wday]); printf(\ return pstr; }

//结账付钱后 要把住客住的房间给空出来 void delete_the_house_person(link_guest p) { int i=0;

for (i=0;i<10;i++) { if (strcmp(p->room,h[i].house_number)==0) { h[i].sum_person=0; return ; } } };

link_guest pay_for_house(link_guest head) { char str[10]; link_guest p; struct tm *pstr; float money; // printf(\结账的住客的名字:\\n\ // scanf(\ p=head; if (is_null_guest(p)) { printf(\当前没有任何住客的信息!\\n\ return head; } else { printf(\输入你想要结账客户的名字:\\t\ scanf(\ while (p->next!=NULL&&(strcmp(p->next->name,str)!=0)) { p=p->next; } if (p->next==NULL) { printf(\ printf(\没有该住客的信息!\\n\

printf(\ return head; } else { p=p->next; printf_detail_now(p); printf(\结账时间:\\t\\t\ pstr=pay_for_time(); //pay_for_house_money(pstr,p); money=pay_for_house_money(pstr,p); delete_the_house_person(p); printf(\住客应付:\\t\\t%.2f元\ printf(\ } } return head; }

void main() { int choice; link_guest head=create_guest(); do { //system(\清屏函数 printf(\酒店房间登记与计费管理系统----\\n\ printf(\登记入住\\n\ printf(\查询房间的入住情况\\n\ printf(\删除客户\\n\

printf(\查询住客\\n\

printf(\修改住客的信息:\\n\

printf(\查询所有的客房信息:\\n\

printf(\空余客房查询:\\n\// printf(\查询当前费用\\n\// printf(\结账退房\\n\

printf(\结账退房:\\n\

printf(\清空屏幕:\\n\

printf(\退出程序\\n\

printf(\

printf(\请选择:\\t\

scanf(\

printf(\

if (choice>10||choice<0) { printf(\对不起!没有这个选项 !\\n\ continue; }

switch (choice) { case 1: head=insert_guest(head); break; case 2: printf_guest(head); break; case 3: head=delete_guest(head); break;

}

case 4: lookfor_guest(head); break; case 5: head=modify_guest(head); break; case 6: // printf(\你要查询的是:1.单人间 2.双人间 3.多人间 4.退出:\\n\ // printf(\你的选择是:\\t\ // scanf(\ printf_all_house(); break; case 7: lookfor_house_is_Null(); break; case 8: pay_for_house(head); break; case 9: system(\ break; case 10: printf(\系统已退出!\\n\ exit(1); break; default: break; }

} while(choice!=10);

}

case 4: lookfor_guest(head); break; case 5: head=modify_guest(head); break; case 6: // printf(\你要查询的是:1.单人间 2.双人间 3.多人间 4.退出:\\n\ // printf(\你的选择是:\\t\ // scanf(\ printf_all_house(); break; case 7: lookfor_house_is_Null(); break; case 8: pay_for_house(head); break; case 9: system(\ break; case 10: printf(\系统已退出!\\n\ exit(1); break; default: break; }

} while(choice!=10);

本文来源:https://www.bwwdw.com/article/cbf3.html

Top