当前位置:首页 » 编程语言 » c语言的酒店管理系统

c语言的酒店管理系统

发布时间: 2022-07-11 06:23:29

c语言酒店管理系统

20分?我倒
给个建构你,至于怎么实现自己想办法了
struct Hotel
{
int index;//客房编号;
int type;//客房类型;
int position;//客房位置;
int area;//面积;
int bedsOfRoom;//床位数;
int price;//价格
Hotel*next;
};

Ⅱ 请问高手 用C语言怎样编程酒店管理系统!

留个EMAIL,发一个VC做的完整项目让你参考下.

Ⅲ 求酒店管理系统(C语言)

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct customers_node{
char id[18];
int days;
int money;
char roomnumber[3];
struct customers_node *next;
};
struct customers_node * p0,* head;
//#define N 100
struct customers_node * Create_Cust_Doc(); //新建
struct customers_node * InsertDoc(struct customers_node * head,char id[ ]); //插入
struct customers_node * DeleteDoc(struct customers_node * head,char id[ ]); //删除
struct customers_node * searchDoc(struct customers_node * head,char id[ ]); //查询
void Print_Cust_Doc(struct customers_node * head); //调用信息函数
struct customers_node * customers(struct customers_node * p0); //需要为p0分配动态存储空间吗
int main(void)
{
struct customers_node * head;
int choice;
char id[18];
do{
printf("本系统功能:\n");
printf("1.Create(新建) 2.search(查询) 3.Insert(添加) 4.Delete(删除) 5.print 0:Exit(退出)\n");
printf("请选择:");
scanf("%d",&choice);
switch(choice){
case 1:
head=Create_Cust_Doc();
break;
case 2:
printf(" 请您输入您的身份证号码:\n");
scanf("%s",id);
head=searchDoc(head,id);
break;
case 3:
printf(" 请您输入您的身份证号码:\n");
scanf("%s",id);
head=InsertDoc(head,id);
break;
case 4:
printf(" 请您输入您的身份证号码:\n");
scanf("%s",id);
head=DeleteDoc(head,id);
break;
case 5:
Print_Cust_Doc(head);
break;
case 0:
break;
}
}while(choice!=0);
return 0;
}
struct customers_node * customers(struct customers_node * p0)
{
struct customers_node * p;
int days,money,choice,z;
char id[18];
char roomnumber[3];
printf(" 请您输入您的身份证号码:\n");
scanf("%s",id);
printf(" 您已登陆成功!\n");
printf(" 请您选择房间种类:\n");
printf(" 1.单人间/夜150元\n 2.双人间/夜200元\n 3.标准间/夜300元\n 4.总统套房/夜600元\n");
scanf("%d",&choice);
switch(choice) {
case 1:printf(" 请输入预定天数\n");
scanf("%d",&days);
money=days*150;
printf(" 请预交款为%d元\n",money);
printf(" 1.确定(预定成功) 2.返回(是否重新预定)\n");
scanf("%d",&z);
if(z==1){
printf(" 您已预定成功 ★ 房间号码为: ");
scanf("%s",roomnumber);
}break;

case 2:printf(" 请输入预定天数\n");
scanf("%d",&days);
money=days*200;
printf(" 请预交款为%d元\n",money);
printf(" 1.确定(预定成功) 2.返回(是否重新预定)\n");
scanf("%d",&z);
if(z==1){
printf(" 您已预定成功★房间号码为: ");
scanf("%s",roomnumber);
}break;

case 3:printf(" 请输入预定天数: ");
scanf("%d",&days);
money=days*300;
printf(" 请预交款为%d元\n",money);
printf(" 1.确定(预定成功) 2.返回(是否重新预定)\n");
scanf("%d",&z);
if(z==1){
printf(" 您已预定成功 ★ 房间号码为: ");
scanf("%s",roomnumber);
} break;

case 4:printf(" 请输入预定天数\n");
scanf("%d",&days);
money=days*600;
printf(" 请预交款为%d元\n",money);
printf(" 1.确定(预定成功) 2.返回(是否重新预定)\n");
scanf(" %d",&z);
if(z==1){
printf(" 您已预定成功★房间号码为: ");
scanf("%s",roomnumber);
}break;
default :printf(" 您的输入有错,请您重试,谢谢。\n");
break;
p=(struct customers_node *)malloc(sizeof(struct customers_node)); //是否能用指针完成结构元素的传送
strcpy(p->id,id);
strcpy(p->roomnumber,roomnumber);
p->days=days;
p->money=money;
return p;
}
struct customers_node * Create_Cust_Doc() //新建
{
struct customers_node * head,* p;
int size=sizeof(struct customers_node);
p=(struct customers_node *)malloc(size);
head->next = NULL;
customers(* p0); //调用函数
//p=p0;
head->next=p;
return head;
}

struct customers_node * InsertDoc(struct customers_node * head);
{
struct customers_node *q,*temp;
q=(struct customers_node *)malloc(sizeof(struct customers_node));
customers(p0);
temp=p0; //未解决元素的插入
q=head->next;
if(head->next==NULL){
q=temp;
q->next=NULL;
}
while(q->next) q=q->next;
q->next=temp;
return head;
}

struct customers_node * searchDoc(struct customers_node * head,char id) //是否只用id能返回结构中的所有元素
{
struct customers_node * p=head->next;
p=head->next;
if(head->next==null)
printf("无人入住");
else{
while(strcmp(id,p->id)!=0) //如何只用id表示结点(结构)中的数据部分 p=p->next;
p=p->next;
}
return p;
}

struct customers_node * DeleteDoc(struct customers_node * head,char id)
{
struct customers_node * p,* q;
p=head->next;
q=p->next;
if(p==null)
return null;
while(p!=null){
if(strcmp(id,p->id)==0){
q=p;
free(p);
}
p=p->next;
q=p->next;
}
return head;
}
void Print_Cust_Doc(struct customers_node * head)
{
struct customers_node * q;
if(head->next==null){
printf("\n 没有记录\n");
return ;
}
printf("入住客户记录是:\n");
for(q=head->next;q;q=q->next){
printf(" 身份证号码:%s\t",q->id);
printf(" 入住天数:%d\t",q->days);
printf(" 预交款:%d\t",q->money);
printf(" 房间号:%s\n",q->roomnumber);
}
}

Ⅳ C语言实现酒店信息管理系统

不知道你的要求是什么,把我以前的关于酒店管理的代码发给你参考下吧。

#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
typedefstructtagCustomer
{
charm_ID[19];/*身份证号码*/
charm_name[10];/*顾客姓名*/
intm_age;/*顾客年龄*/
charm_sex[6];/*顾客性别*/
intnum;
}Customer;/*顾客结构*/

typedefstructtagRoom
{
intm_num;/*房间号*/
intm_floor;/*楼层*/
intm_price;/*价格*/
intm_use;/*是否已入住*/
}Room;/*房间结构*/
inti,j=0,age,num,floor,price,use,n;
intreg=0;
Customercus[5];
Roomr[5];
intcount=5;
charID[18],name[10],sex[6];
FILE*fproom;
FILE*fpcustomer;

voidCustomer_Input()
{
if(count<=5)
{
printf("请输入身份证号(18位数字):");
scanf("%s",&cus[j].m_ID);
printf("请输入姓名(10位字符)");
scanf("%s",&cus[j].m_name);
printf("请输入年龄(数字型)");
scanf("%d",&cus[j].m_age);
printf("请输入性别(男或女):");
scanf("%s",&cus[j].m_sex);
}
else
{
printf(" 存储空间已满!");
}
printf(" 顾客可以住在:");
printf(" 房间号楼层价格是否空闲(1:空闲0:已使用)");
for(i=0;i<count;i++)
{
if(r[i].m_use==1)
{
printf(" %d%d%d%d",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
}
}
printf(" 请你输入房间号:");
scanf("%d",&num);
reg=0;
for(i=0;i<count;i++)
{
if(r[i].m_use==1&&r[i].m_num==num)
{
r[i].m_use=0;
printf(" 登记成功! ");
cus[j].num=r[i].m_num;
j=j+1;
reg=1;
}
}
if(reg==0)
{
printf(" 登记失败! ");
}

}
voidCustomer_ListOut()
{
if(count<=5)
{
printf("请输入身份证号(18位数字):");
scanf("%s",&ID);
for(i=0;i<count;i++)
{
if(strcmp(cus[i].m_ID,ID)==0)
{
printf(" 顾客身份证号:%s姓名:%s年龄:%d性别:%s ",cus[i].m_ID,cus[i].m_name,cus[i].m_age,cus[i].m_sex);
}
}
}
else
{
printf(" ");
}
}
voidRoom_ListOut()
{
printf(" 房间号楼层价格是否空闲(1:空闲0:已使用)");
for(i=0;i<count;i++)
{
if(r[i].m_use==1)
{
printf(" %d%d%d%d",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
}
}
}
voidPerCustomer_Search()
{
if(count<=5)
{
printf("请输入身份证号(18位数字):");
scanf("%s",&cus[j].m_ID);
printf("请输入姓名(10位字符)");
scanf("%s",&cus[j].m_name);
printf("请输入年龄(数字型)");
scanf("%d",&cus[j].m_age);
printf("请输入性别(男或女):");
scanf("%s",&cus[j].m_sex);
}
else
{
printf(" 住房已满!");
}
printf(" 顾客可以预订:");
printf(" 房间号楼层价格是否空闲(1:空闲0:已使用)");
for(i=0;i<count;i++)
{
if(r[i].m_use==1)
{
printf(" %d%d%d%d",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
}
}
printf(" 请你输入要预订的房间号:");
scanf("%d",&num);
reg=0;
for(i=0;i<count;i++)
{
if(r[i].m_use==1&&r[i].m_num==num)
{
r[i].m_use=0;
printf(" 预订成功! ");
cus[j].num=r[i].m_num;
j=j+1;
reg=1;
}
}
if(reg==0)
{
printf(" 预订失败! ");
}
}
voidUnCustomer_Out()
{
intk;
printf(" 请输入要退房顾客身份证:");
scanf("%s",&ID);
for(i=0;i<count;i++)
{
if(strcmp(cus[i].m_ID,ID)==0)
{
printf(" 顾客身份证号:%s姓名:%s年龄:%d性别:%s 已经成功退房!",cus[i].m_ID,cus[i].m_name,cus[i].m_age,cus[i].m_sex);
for(k=0;k<count;k++)
if(r[k].m_num==cus[i].num)
r[k].m_use=1;
memset(&cus[i],0,sizeof(Customer));

}
}
}
voidCustomer_Goaway()
{
fproom=fopen("room","wb+");
fwrite((void*)&r,sizeof(Room),count,fproom);
fclose(fproom);

fpcustomer=fopen("customer","wb+");
fwrite((void*)&r,sizeof(Room),count,fpcustomer);
fclose(fpcustomer);
exit(0);

}
main()
{
fproom=fopen("room","wb");
if(fproom!=NULL)
{
for(i=0;i<count;i++)
{
intid=100;
r[i].m_num=i+100;
r[i].m_floor=1;
r[i].m_price=100;
r[i].m_use=1;
}
fwrite((void*)&r,sizeof(Room),count,fproom);
fclose(fproom);
}
else
{
printf(" ---文件打开失败--");
}
for(;;)
{

printf(" ");
printf("/******************************************\ ");
printf("** ");
printf("*酒店管理系统* ");
printf("*主菜单* ");
printf("** ");
printf("*1.顾客登记* ");
printf("*2.查询顾客信息* ");
printf("*3.查询空房间* ");
printf("*4.预订房间* ");
printf("*5.退订房间* ");
printf("*6.保存并退出系统* ");
printf("** ");
printf("\******************************************/ ");
printf("请输入选择项(1-6):");
scanf("%d",&n);
printf(" ");
if(n>0&&n<=6)
{
switch(n)
{
case1:Customer_Input();break;
case2:Customer_ListOut();break;/*查询顾客信息*/
case3:Room_ListOut();break;/*查询空房间*/
case4:PerCustomer_Search();break;/*预订房间*/
case5:UnCustomer_Out();break;/*退订房间*/
case6:Customer_Goaway();/*保存退出*/
}
}
else
{
printf("*********************************************************************** ");
printf("** ");
printf("*输入错误!* ");
printf("*请退出!* ");
printf("** ");
printf("*********************************************************************** ");
break;
}
}
}

Ⅳ 请哪位高手帮我用C语言编一个酒店管理系统软件 ! 急!!!

#define NULL 0
#define LEN sizeof(struct customer)
#include "string.h"
struct customer
{
int num;
char name[20];
long date;
struct customer *next;
}cus;
struct customer *creat(void) /*建立一个链表*/
{
struct customer *head,*p1,*p2;
int n=0;
p1=(struct customer *)malloc(LEN);
p2=(struct customer *)malloc(LEN);
printf("请输入客户的信息:\n");
printf("\n房间:");
scanf("%d",&p1->num);
printf("\n");
printf("姓名:");
scanf("%s",p1->name);
printf("\n");
printf("入住时间:");
scanf("%ld",&p1->date);
printf("\n");
head=NULL;
while(p1->num!=0)
{
n++;
if(n==1)
head=p1;
else
p2->next=p1;
p2=p1;
p1=(struct customer *)malloc(LEN);
printf("请输入客户的信息:\n");
printf("\n房间:");
scanf("%d",&p1->num);
printf("\n");
printf("姓名:");
scanf("%s",p1->name);
printf("\n");
printf("入住时间:");
scanf("%ld",&p1->date);
printf("\n");
}
p2->next=NULL;
return(head);
}
struct customer *insert(struct customer *head,struct customer *consumer) /*登记新入住的客户的信息*/
{
struct customer *p1,*p2;
p1=head;
p2=consumer;
if(p1->next!=NULL)
p1=p1->next;
if(p1->next==NULL)
{
p1->next=p2;
p2->next=NULL;
}
return(head);
}
struct customer *del(struct customer *head,int num) /*显示退房客户的信息*/
{
struct customer *p1,*p2;
if(head==NULL)
{
printf("没有客户的信息\n");
return(head);
}
p1=head;
while(num!=p1->num&&p1->next!=NULL)
{
p2=p1;p1=p1->next;
}
if(num==p1->num)
{
if(p1==head)
head=p1->next;
else
p2->next=p1->next;
printf("退房客户的信息:\n");
printf("客房:%d\n",&p1->num);
printf("姓名:%s\n",p1->name);
printf("入住时间:%ld\n",&p1->date);
}
else
printf("没有该客户的信息\n");
return(head);
}
struct customer *search(struct customer *head,char c_name[]) /*查询客户信息*/
{
struct customer *p;
p=head;
while(strcmp(p->name,c_name)&&p->next!=NULL)
p=p->next;
if(p->name==c_name)
{
printf("该客户的信息为:\n");
printf("房间:%d\n姓名:%S\n入住时间:%ld",p->num,p->name,p->date);
}
if(p->name!=c_name&&p->next==NULL)
printf("没有该客户的信息!\n");
}
void print(struct customer *head) /*打印出现有客户的信息*/
{
struct customer *p;
printf("\n现有客户信息为:\n");
p=head;
if(head!=NULL)
do
{
printf("客房:%d\n",p->num);
printf("姓名:%s\n",p->name);
printf("入住时间:%ld\n",p->date);
p=p->next;
}while(p!=NULL);
}
main()
{
struct customer *head,*p;
int m,number;
char c_name[20];
printf("\n");
printf(" ******************************\n");
printf(" 欢迎进入旅游信息管理系统\n");
printf(" ******************************\n");
printf(" ******************************\n\n");
printf(" 1:建库\n");
printf(" 2:登记\n");
printf(" 3:退房\n");
printf(" 4:查询\n");

printf(" ******************************\n\n");
printf("请执行操作:\n");
scanf("%d",&m);
if(m==1)
head=creat();
else
if(m==2)
{
printf("请输入要登记得客户的信息:");
p=(struct customer *)malloc(LEN);
scanf("%d %s %ld",&p->num,p->name,&p->date);
head=insert(head,p);
print(head);
}
else
if(m==3)
{
printf("请输入要退房的客户的房间号:");
scanf("%d",&number);
head=del(head,number);
print(head);
}

else
if(m==4)
{
printf("请输入要查询的客户的姓名:");
scanf("%s",c_name);
search(head,c_name);
}
else
printf("执行操作错误!");
}

有5个警告而已,不过已经很不错了

Ⅵ 请高手帮忙用C语言做一个酒店管理系统

在这个经济社会里谁还会免费的帮人家出这么大的力啊?你那酒店管理系统要求再简单也要花时间啊!再说你要它的原理,这不是要人家的知识产权吗?也许人家开发出来把软件打包给你还有可能。

Ⅶ 用c语言写酒店管理系统时如何用时间库自动生成入房日期

也就是要获取系统时间,下面是c语言的代码截图,读取系统时间,如下:

获取系统时间

Ⅷ C语言编程,关于酒店信息管理方面的

不知道你的要求是什么,把我以前的关于酒店管理的代码发给你参考下吧。

#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
typedef struct tagCustomer
{
char m_ID[19]; /*身份证号码*/
char m_name[10]; /*顾客姓名*/
int m_age; /*顾客年龄*/
char m_sex[6]; /*顾客性别*/
int num;
}Customer;/*顾客结构*/

typedef struct tagRoom
{
int m_num; /*房间号*/
int m_floor; /*楼层*/
int m_price; /*价格*/
int m_use; /*是否已入住*/
}Room;/*房间结构*/
int i,j=0,age,num,floor,price,use,n;
int reg =0;
Customer cus[5];
Room r[5];
int count=5;
char ID[18],name[10],sex[6];
FILE *fproom;
FILE *fpcustomer;

void Customer_Input()
{
if(count<=5)
{
printf("请输入身份证号(18位数字):");
scanf("%s",&cus[j].m_ID);
printf("请输入姓名(10位字符)");
scanf("%s",&cus[j].m_name);
printf("请输入年龄(数字型)");
scanf("%d",&cus[j].m_age);
printf("请输入性别(男或女):");
scanf("%s",&cus[j].m_sex);
}
else
{
printf("\n 存储空间已满!");
}
printf("\n\r顾客可以住在:");
printf("\n\r房间号 楼层 价格 是否空闲(1:空闲0:已使用)");
for(i=0;i<count;i++)
{
if(r[i].m_use==1)
{
printf("\n\r%d %d %d %d ",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
}
}
printf("\n\r请你输入房间号:");
scanf("%d",&num);
reg = 0;
for(i=0;i<count;i++)
{
if(r[i].m_use==1&&r[i].m_num==num)
{
r[i].m_use = 0;
printf("\n 登记成功!\n");
cus[j].num=r[i].m_num ;
j=j+1;
reg=1;
}
}
if(reg==0)
{
printf("\n 登记失败!\n");
}

}
void Customer_ListOut()
{
if(count<=5)
{
printf("请输入身份证号(18位数字):");
scanf("%s",&ID);
for(i=0;i<count;i++)
{
if(strcmp(cus[i].m_ID,ID)==0)
{
printf("\n\r顾客身份证号:%s 姓名:%s 年龄:%d 性别:%s \n",cus[i].m_ID,cus[i].m_name,cus[i].m_age,cus[i].m_sex);
}
}
}
else
{
printf("\n \n");
}
}
void Room_ListOut()
{
printf("\n\r房间号 楼层 价格 是否空闲(1:空闲0:已使用)");
for(i=0;i<count;i++)
{
if(r[i].m_use==1)
{
printf("\n\r%d %d %d %d ",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
}
}
}
void PerCustomer_Search()
{
if(count<=5)
{
printf("请输入身份证号(18位数字):");
scanf("%s",&cus[j].m_ID);
printf("请输入姓名(10位字符)");
scanf("%s",&cus[j].m_name);
printf("请输入年龄(数字型)");
scanf("%d",&cus[j].m_age);
printf("请输入性别(男或女):");
scanf("%s",&cus[j].m_sex);
}
else
{
printf("\n 住房已满!");
}
printf("\n\r顾客可以预订:");
printf("\n\r房间号 楼层 价格 是否空闲(1:空闲0:已使用)");
for(i=0;i<count;i++)
{
if(r[i].m_use==1)
{
printf("\n\r%d %d %d %d ",r[i].m_num,r[i].m_floor,r[i].m_price,r[i].m_use);
}
}
printf("\n 请你输入要预订的房间号:");
scanf("%d",&num);
reg = 0;
for(i=0;i<count;i++)
{
if(r[i].m_use==1&&r[i].m_num==num)
{
r[i].m_use = 0;
printf("\n 预订成功!\n");
cus[j].num=r[i].m_num ;
j=j+1;
reg=1;
}
}
if(reg==0)
{
printf("\n 预订失败!\n");
}
}
void UnCustomer_Out()
{
int k;
printf("\n 请输入要退房顾客身份证:");
scanf("%s",&ID);
for(i=0;i<count;i++)
{
if(strcmp(cus[i].m_ID,ID)==0)
{
printf("\n\r顾客身份证号:%s 姓名:%s 年龄:%d 性别:%s \n\r已经成功退房!",cus[i].m_ID,cus[i].m_name,cus[i].m_age,cus[i].m_sex);
for(k=0;k<count;k++)
if(r[k].m_num==cus[i].num)
r[k].m_use=1;
memset(&cus[i],0,sizeof(Customer));

}
}
}
void Customer_Goaway()
{
fproom=fopen("room","wb+");
fwrite((void *)&r,sizeof(Room),count,fproom);
fclose(fproom);

fpcustomer=fopen("customer","wb+");
fwrite((void *)&r,sizeof(Room),count,fpcustomer);
fclose(fpcustomer);
exit(0);

}
main()
{
fproom=fopen("room","wb");
if(fproom!=NULL)
{
for(i=0;i<count;i++)
{
int id=100;
r[i].m_num=i+100;
r[i].m_floor=1;
r[i].m_price=100;
r[i].m_use=1;
}
fwrite((void *)&r,sizeof(Room),count,fproom);
fclose(fproom);
}
else
{
printf("\n---文件打开失败--");
}
for(;;)
{

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("* *\n");
printf("\\******************************************/\n\n");
printf("请输入选择项(1-6):");
scanf("%d",&n);
printf("\n\n\n\n");
if(n>0&&n<=6)
{
switch(n)
{
case 1:Customer_Input();break;
case 2:Customer_ListOut();break;/*查询顾客信息*/
case 3:Room_ListOut();break;/*查询空房间*/
case 4:PerCustomer_Search();break;/*预订房间*/
case 5:UnCustomer_Out();break;/*退订房间*/
case 6:Customer_Goaway(); /*保存退出*/
}
}
else
{
printf("***********************************************************************\n");
printf("* *\n");
printf("* 输入错误! *\n");
printf("* 请退出! *\n");
printf("* *\n");
printf("***********************************************************************\n");
break;
}
}
}

Ⅸ C语言编写酒店管理系统

int CheckRoom(struct room *pr)
{char phonenu[4][12]={"110","119","120","122"};/*非法私人电话号码*/
char type[3][2]={"2","t","T"};
int flag=1,i;
static int pass=1;

if(NULL==pr) {printf("Error:Null point! Can't check the datas:\n");return 0;}

printf("Start to part Maintain:about room\n");

while( strlen(pr->roomnu)>5 )/*检查数据长度,防止保存二进制数据错误*/
{pr->roomnu[5]=0;
printf("ERROR:the roomnu: %s is longer than 5 bytes.\n",pr->roomnu);
printf("Please select another shorter roomnu:\n");
scanf("%s",pr->roomnu);
}

while( strlen(pr->cleaner)>19 )/*检查数据长度,防止保存二进制数据错误*/
{pr->cleaner[19]=0;
printf("ERROR:the cleaner:%s is longer than 19 bytes.\n",pr->cleaner);
printf("Please select another shorter name:\n");
scanf("%s",pr->cleaner);
}

while(flag||strlen(pr->phonenu)>11)/*检查数据内容(由flag控制)和长度,防止保存二进制数据错误*/
{
while( strlen(pr->phonenu)>11 )/*检查长度*/
{pr->phonenu[11]=0;
printf("ERROR:the phonenu:%s is longer than 11 bytes.\n",pr->phonenu);
printf("Please select another shorter phonenu:\n");
scanf("%s",pr->phonenu);
}
while(flag)/*检查内容*//*这个算法也有问题,如果内容非法,但长度通过怎么办呢?*/
{for(i=0;flag&&i<4;i++)
if( 0==strcmp(pr->phonenu,phonenu[i]) )/*内容非法*/
{printf("ERROR:illegal phonenu:%s!\n",pr->phonenu);
flag=0;/*检测到内容非法*/
}
if(flag) flag=0;/*内容检查通过*/
else {flag=1;
printf("Please input a legal phonenu:\n");
scanf("%s",pr->phonenu);/*内容检查未通过,重新收入*/
}
}
}

flag=1;
while(flag||strlen(pr->type)>1)/*检查数据内容(由flag控制)和长度,此例和上例不同*/
{
while( strlen(pr->type)>1 )/*检查长度*/
{pr->type[1]=0;
printf("ERROR:the type:%s is longer than 1 byte.\n",pr->type);
printf("Please select another shorter type:\n");
scanf("%s",pr->type);
}
while(flag)/*检查内容*/
{if(strcmp(pr->type,type[0])&&strcmp(pr->type,type[1])&&strcmp(pr->type,type[2]) )/*内容非法*/
{printf("ERROR:illegal type:%s!\n",pr->type);
flag=0;/*检测到内容非法*/
}

if(flag) flag=0;/*内容检查通过*/
else {flag=1;
printf("Please input a legal type:\n");
scanf("%s",pr->type);/*内容检查未通过,重新收入*/
}
}
}

while( pr->maximum<pr->currentclient )/*检查数据间的联系*/
{printf("ERROR:the room's capacity does not fit for the number of current clients.\n");
printf("Please alter the maximum:\n");
scanf("%d",&(pr->maximum));
}/*检查房间最大容量和当前已住顾客人数是否相容,如果前者小于后者则写入错误报告文件 */

printf("Congratulations: ROOM Check pass %d!\n",pass++);
return 1;
}

int CheckClient(struct client *pc)
{ int flag=1,i;
char sex[4][2]={"m","M","f","F"};
static int pass=1;

if(NULL==pc) {printf("Error:Null point! Can't check the datas:\n");return 0;}

printf("Start to part Maintain:about client\n");

while( strlen(pc->roomnu)>5 )/*检查房间长度*/
{pc->roomnu[5]=0;
printf("ERROR:the roomnu: %s is longer than 5 bytes.\n",pc->roomnu);
printf("Please select another shorter roomnu:\n");
scanf("%s",pc->roomnu);
}

while( strlen(pc->identity_card)!=18 )/*检查身份证号长度*/
{pc->identity_card[18]=0;
printf("ERROR:the identity_card:%s is not 18 bytes.\n",pc->identity_card);
printf("Please check the length and input it again:\n");
scanf("%s",pc->identity_card);
}

while(strlen(pc->name)>19)/*检查姓名长度*/
{pc->name[19]=0;
printf("ERROR:the name:%s is longer than 19 bytes.\n",pc->name);
printf("Please select another shorter phonenu:\n");
scanf("%s",pc->name);
}

while(flag||strlen(pc->sex)>1)/*检查性别内容(由flag控制)和长度*/
{
while( strlen(pc->sex)>1 )/*检查长度*/
{pc->sex[1]=0;
printf("ERROR:the sex:%s is longer than 1 byte.\n",pc->sex);
printf("Please select another shorter sex:\n");
scanf("%s",pc->sex);
}
while(flag)/*检查内容*/
{if(strcmp(pc->sex,sex[0])&&strcmp(pc->sex,sex[1])&&strcmp(pc->sex,sex[2])&&strcmp(pc->sex,sex[3]) )/*内容非法*/
{printf("ERROR:illegal sex:%s!\n",pc->sex);
flag=0;/*检测到内容非法*/
}
if(flag) flag=0;/*内容检查通过*/
else {flag=1;
printf("Please input a legal sex:\n");
scanf("%s",pc->sex);/*内容检查未通过,重新收入*/
}
}
}

while( strlen(pc->date)!=8 )/*检查日期长度*/
{pc->date[8]=0;
printf("ERROR:the date:%s is not 8 bytes.\n",pc->date);
printf("Please check the length and input it again:\n");
scanf("%s",pc->date);
}

while( strlen(pc->collect)>5 )/*检查收款人长度*/
{pc->collect[5]=0;
printf("ERROR:the collect:%s is not 5 bytes.\n",pc->collect);
printf("Please check the length and input it again:\n");
scanf("%s",pc->collect);
}

while(pc->time<0)/*检查入住天数*/
{printf("ERROR:illegal input of time: %f!\n",pc->time);
printf("Please check and input it again:\n");
scanf("%f",&pc->time);
}

while(pc->cost<0)/*检查应缴费用*/
{printf("ERROR:illegal input of cost: %f!\n",pc->cost);
printf("Please check and input it again:\n");
scanf("%f",&pc->cost);
}

while(pc->fee<0)/*检查实缴费用*/
{printf("ERROR:illegal input of cost: %f!\n",pc->fee);
printf("Please check and input it again:\n");
scanf("%f",&pc->fee);
}

if( pc->fee>pc->cost )/*检查数据间的联系,实缴费用应小于应缴用*/
{printf("It may be a error:fee=%f > cost=%f\n",pc->fee,pc->cost);
printf("Do you like to alter them?(1:YES;0:NO)\n");
scanf("%d",&flag);
while(flag)
{printf("Please input the values:cost and fee\n");
scanf("%f%f",&pc->cost,&pc->fee);
if(pc->fee>pc->cost)
{printf("Error again!!\n");flag=1;}
else flag=0;
}
}

printf("Congratulations: CLIENT Check pass %d!\n",pass++);
return 1;
}

int CheckAll(struct room *head_room)
{struct client *pc;
struct room *pr;

if(NULL==head_room) {printf("head_room=0\n");return 0;}

printf("Start to part Maintain:about room and client\n");

pr=head_room;
while(pr)
{CheckRoom(pr);
pc=pr->head;
while(pc)
{CheckClient(pc);
pc=pc->next;
}
pr=pr->next;
}

return 1;
}

/**该函数为内部数据维护,不提供输入数据服务。实体完整性,参照完整性,用户自定义完整性
出现错误则将错误输出到doc文档。
错误范围暂时定义如下:
1.同一房间的客户房间号不同(同房搜索!)

2.实缴费用大于应缴费用。(同房搜索!)

3.同一个客户在同一天两次住进宾馆(全表搜索!身份证号和入住日期相同)

4.同一身份证号,姓名和性别不同(全表搜索!)

另外,应该完成的任务有:
5.计算客户的应缴费用->对cost操作,需要用到:time,unit_price

6.计算客房的总住户人数(包括当前住户)->对totalclient操作,需要用到:没有

7.重新修订当前住户数->对currentclient进行操作,需要用到:time

8.计算客房的总计收入->对income进行操作,需要用到:fee

9.当前住户的实缴费用清零->对fee进行操作,需要用到:time

完成这些操作的先后顺序为:7->6->5->9->8->2->1->3->4*/

int Consistency(struct room *head_room)
{struct room *pr,*tpr;
struct client *pc,*tpc;
char file[12]="error.doc";
int i=0;/*i用于错误计数*/
static int count=0;
FILE *fp;

if(NULL==head_room) {printf("head_room=0\n");return 0;}

printf("Start to part Maintain:Consistency!\n");

pr=head_room;
while(pr)
{pr->currentclient=0;
/*pr->totalclient=0;*/
pr->income=0;

pc=pr->head;
while(pc)
{if(!pc->time) pr->currentclient++;/*完成........7.....*/
/*pr->totalclient++;*/ /*完成........6.....*/
pc->cost=(pc->time)*(pr->unit_price); /*完成........5.....*/
if(!pc->time) pc->fee=0; /*完成........9.....*/
pr->income=pr->income+pc->fee; /*完成........8.....*/

pc=pc->next;
}

pr=pr->next;
}

if(NULL==( fp=fopen(file,"wt") ) )
{printf("Cannot open file:%s!\n",file);
return 0;
}

pr=head_room;
while(pr)
{pc=pr->head;
while(pc)
{if(pc->fee>pc->cost)
{fprintf(fp,"Error %d:fee=%f > cost=%f\n",++i,pc->fee,pc->cost);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
/*完成........2.....*/
}

if( strcmp(pr->roomnu,pc->roomnu) )
{fprintf(fp,"Error %d:the client's roomnu:%s != the room's roomnu:%s",++i,pc->roomnu,pr->roomnu);
fprintf(fp,"roomnu cleaner phonenu type max area price clientNO\n");
fprintf(fp,"%-6s %-16s %-12s %-4s %-3d %-6.1f %-6.1f %-2d\n",pr->roomnu,pr->cleaner,pr->phonenu,pr->type,pr->maximum,pr->area,pr->unit_price,pr->currentclient);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
/*完成........1.....*/
}
pc=pc->next;
}
pr=pr->next;
}

/*这个要全表搜索,搜索一次全表过掉一个客户*/
pr=head_room;
while(pr)
{pc=pr->head;
while(pc)
{
if(pc->next)
{tpc=pc->next;
while(tpc)
{if(0==strcmp(pc->identity_card,tpc->identity_card) && 0==strcmp(pc->date,tpc->date) )
{fprintf(fp,"Error %d:the same client:%s lived in our hotel in the same day:%s\n",++i,pc->identity_card,pc->date);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",tpc->roomnu,tpc->identity_card,tpc->name,tpc->sex,tpc->date,tpc->collect,tpc->time,tpc->cost,tpc->fee);
}/*完成........3.....*/

if(0==strcmp(pc->identity_card,tpc->identity_card) && (strcmp(pc->name,tpc->name)||strcmp(pc->sex,tpc->sex)) )
{fprintf(fp,"Error %d:the same client:%s have the different name or sex in our hotel.\n",++i,pc->identity_card);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",tpc->roomnu,tpc->identity_card,tpc->name,tpc->sex,tpc->date,tpc->collect,tpc->time,tpc->cost,tpc->fee);
}/*完成........4.....*/
tpc=tpc->next;
}/*while(tpc) exit */

/*当前房间比较结束,进入下一个房间*/
tpr=pr->next;
while(tpr)
{tpc=tpr->head;
while(tpc)
{if(0==strcmp(pc->identity_card,tpc->identity_card) && 0==strcmp(pc->date,tpc->date) )
{fprintf(fp,"Error %d:the same client:%s lived in our hotel in the same day:%s\n",++i,pc->identity_card,pc->date);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",tpc->roomnu,tpc->identity_card,tpc->name,tpc->sex,tpc->date,tpc->collect,tpc->time,tpc->cost,tpc->fee);
}/*完成........3.....*/

if(0==strcmp(pc->identity_card,tpc->identity_card) && (strcmp(pc->name,tpc->name)||strcmp(pc->sex,tpc->sex)) )
{fprintf(fp,"Error %d:the same client:%s have the different name or sex in our hotel.\n",++i,pc->identity_card);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",tpc->roomnu,tpc->identity_card,tpc->name,tpc->sex,tpc->date,tpc->collect,tpc->time,tpc->cost,tpc->fee);
}/*完成........4.....*/
tpc=tpc->next;
}/*while(tpc) exit */
tpr=tpr->next;
}/*while(tpr) exit */
}

else/*当前客户下一节点为空的情况搜索*/
{tpr=pr->next;
while(tpr)
{tpc=tpr->head;
while(tpc)
{if(0==strcmp(pc->identity_card,tpc->identity_card) && 0==strcmp(pc->date,tpc->date) )
{fprintf(fp,"Error %d:the same client:%s lived in our hotel in the same day:%s\n",++i,pc->identity_card,pc->date);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",tpc->roomnu,tpc->identity_card,tpc->name,tpc->sex,tpc->date,tpc->collect,tpc->time,tpc->cost,tpc->fee);
}/*完成........3.....*/

if(0==strcmp(pc->identity_card,tpc->identity_card) && (strcmp(pc->name,tpc->name)||strcmp(pc->sex,tpc->sex)) )
{fprintf(fp,"Error %d:the same client:%s have the different name or sex in our hotel.\n",++i,pc->identity_card);
fprintf(fp,"roomnu identity_card name sex date clt time cost fee\n");
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n",pc->roomnu,pc->identity_card,pc->name,pc->sex,pc->date,pc->collect,pc->time,pc->cost,pc->fee);
fprintf(fp,"%-6s %-18s %-15s %-3s %-8s %-3s %-4.1f %-5.1f %-5.1f\n\n",tpc->roomnu,tpc->identity_card,tpc->name,tpc->sex,tpc->date,tpc->collect,tpc->time,tpc->cost,tpc->fee);
}/*完成........4.....*/
tpc=tpc->next;
}/*while(tpc) exit */
tpr=tpr->next;
}/*while(tpr) exit */
}

pc=pc->next;/*搜索一次全表过掉一个客户*/
}/*while(pc) exit */
pr=pr->next;
}/*while(pr) exit */

printf("Maintain NO. %d\n",++count);
fclose(fp);
return 1;
}

int ToDate(char *date,int year,int month,int day)/*将年月日转换为字符串*/
{int i,j;
char temp[9];

for(i=3;i>-1;i--)
{j=year%10;
temp[i]=j+'0';
year=year/10;
}

for(i=1;i>-1;i--)
{j=month%10;
temp[4+i]=j+'0';
month=month/10;
}

for(i=1;i>-1;i--)
{j=day%10;
temp[6+i]=j+'0';
day=day/10;
}

temp[8]=0;

strcpy(date,temp);

return 1;
}

int Account(struct room *head_room)
{struct room *pr;
struct client *pc;
char temp[20],date[9],name[6];
float cost,fee;
int time,year,month,day;
int flag=1;
clr();

if(NULL==head_room) {printf("head_room=0\n");getch();clr();return 0;}

printf("Please input CLIENT ID(18bytes)!\n");/*mode=1表示根据身份证号查找特定客户*/
scanf("%s",temp);
while(strlen(temp)!=18)
{printf("Error:the client(ID=%s) is not 18 bytes!",temp);
printf("Please check and input CLIENT ID(18bytes),again!\n");/*mode=1表示根据身份证号查找特定客户*/
scanf("%s",temp);
}

/*查找客户*/
pr=head_room;
flag=1;
while(flag&&pr)
{pc=pr->head;
while(flag&&pc)
{if( !strcmp(pc->identity_card,temp)&&!pc->time)
{printf("roomnu identity_card name sex date clt time cost fee\n");
PrintClient(pc);
flag=0;
}
if(flag) pc=pc->next;
}
pr=pr->next;
}

if(NULL==pc) {printf("Error:the client(ID=%s) does not exist in out hotel!\n",temp);getch();clr();return 0;}
/*获取日期*/
year =GetTime(0,1);
month=GetTime(0,2);
day =GetTime(0,3);

ToDate(date,year,month,day);

time=CountDays(pc->date,date);
cost=time*pr->unit_price;

printf("The client ID=%s who have lived %d days should pay %6.1f $!\n",temp,time,cost);
printf("Please input how much you get from him and your name!\n");
printf("The money is:");
scanf("%f",&fee);
printf("Your name(collect) is:");
scanf("%s",name);

while(strlen(name)>5)
{printf("Error:the name=%s is longer than 5 bytes!",name);
printf("Please check and input ,again!\n");/*mode=1表示根据身份证号查找特定客户*/
scanf("%s",name);
}

pc->fee=fee;
pc->cost=cost;
pc->time=time;
strcpy(pc->collect,name);

printf("Account end! Thank you!\n");
return 1;
}

热点内容
新建文件夹2免费手机 发布:2024-05-18 12:56:13 浏览:363
自己在家搭建服务器有水冷散热吗 发布:2024-05-18 12:47:27 浏览:648
旧版的安卓手机怎么使用微信 发布:2024-05-18 12:46:36 浏览:466
我的世界服务器开多久 发布:2024-05-18 12:45:32 浏览:592
vba获取网页表格数据库数据库数据库 发布:2024-05-18 12:23:24 浏览:699
腾讯服务器为什么卡顿 发布:2024-05-18 12:02:12 浏览:305
如何知道密码锁有没有nfc 发布:2024-05-18 11:58:09 浏览:961
单片机c语言模块化编程 发布:2024-05-18 11:53:16 浏览:644
win7xp共享打印机拒绝访问 发布:2024-05-18 11:51:00 浏览:847
zkeys金属服务器怎么使用 发布:2024-05-18 11:49:31 浏览:581